js/main.js
// Create an initialize function to format the data
Create an initialize function to format the data
Create an initialize function to format the data
function initialize(questions) {
	let selected = questions.sort(() => 0.5 - Math.random()).slice(0, 10);
	let selectedHtml = new Array();
	selected.forEach((question) => {
		let optionsHtml = [];
		question.options.forEach((option) => {
			optionsHtml.push(
				`<div>
			        <input type="radio" id="id-${question.options.indexOf(option)}" name="answer" class="checkbox">
					<label for="id-${question.options.indexOf(option)}">
						<li>${option}</li>
					</label>
				</div>`
			);
		});
		selectedHtml.push(`
			<p class="strong" id="question-text">${selected.indexOf(question) + 1}. ${question.question}</p>
			<form action="" method="GET">
		        <ol class="options">
		            ${shuffle(optionsHtml).join('\n')}
		        </ol>
		        <hr>
		        <div class="navigation">
		            <div class="timer"><p id="timer">01:00</p></div>
		            <div class="next">
		                <button id="next" type="submit">Next</button>
		            </div>
		        </div>
			</form>
			`);
	});
	displayData(selectedHtml, selected);
}
function initialize ( questions ) { let selected = questions . sort ( ( ) => 0.5 - Math . random ( ) ) . slice ( 0 , 10 ) ; let selectedHtml = new Array ( ) ; selected . forEach ( ( question ) => { let optionsHtml = [ ] ; question . options . forEach ( ( option ) => { optionsHtml . push ( ` ${ question . options . indexOf ( option ) } ${ question . options . indexOf ( option ) } ${ option } ` ) ; } ) ; selectedHtml . push ( ` ${ selected . indexOf ( question ) + 1 } ${ question . question } ${ shuffle ( optionsHtml ) . join ( '\n' ) } ` ) ; } ) ; displayData ( selectedHtml , selected ) ; }
Create an initialize function to format the data
Create an initialize function to format the data
// Randomly sort questions and select 5 of them. // console.log(selected); // console.log(optionsHtml);