Question
I need help getting the quiz to go through all of the questions in the array, and displaying a result to the user of what
I need help getting the quiz to go through all of the questions in the array, and displaying a result to the user of what creature they're most like depending on which answers they chose.
Current Code:
document.getElementById('body').style.backgroundColor = 'rgb(0, 177, 0)'; var form = document.getElementById('form-quiz'); form.style.backgroundColor = '#B1FFC3'; form.style.marginLeft = '24%'; form.style.marginTop = '16%'; form.style.marginRight = '24%'; form.style.textAlign = 'center'; form.style.padding = '20px'; var question = document.getElementById('question'); question.style.backgroundColor = 'silver'; var button1 = document.getElementById('1'); button1.style.backgroundColor = 'white'; button1.style.float = 'left'; button1.style.padding = '10px'; button1.style.borderRadius = '7px'; button1.style.marginLeft = '24%'; var button2 = document.getElementById('2'); button2.style.backgroundColor = 'white'; button2.style.float = 'left'; button2.style.padding = '10px'; button2.style.borderRadius = '7px'; button2.style.marginLeft = '29%'; var button3 = document.getElementById('3'); button3.style.backgroundColor = 'white'; button3.style.padding = '10px'; button3.style.borderRadius = '7px'; button3.style.marginTop = '60px'; button3.style.marginLeft = '-600px';
var next = document.getElementById('next'); next.style.backgroundColor = '#5DE4FF'; next.style.borderRadius = '5px'; next.style.marginTop = '20px'; next.style.marginLeft = '500px'; var quiz = [ ['Who could you beat in a fight?','Polar Bear','Pirate Ship', 'Unicorn', '1'], ['What is your favorite condiment?','Barbeque Sauce', 'Wasabi', 'Oyster Sauce', '1'], ['What is your favorite book?','Moby Dick','Fahrenheit 451','The Dunwich Horror','2'] ['Of these animals, which is your favorite?', 'Sandhill Crane', 'Albatross', 'Seagull', '3'] ['What is your favorite video game?', 'Classical', 'Dubstep', 'Rock', '1'] ['Who would you like to narrate your life?', 'Samuel L. Jackson', 'David Tennant', 'Morgan Freeman', '2'] ['What is your favorite video game?', "Assassin's Creed", 'Spyro', 'Super Monkey Ball', '3'] ['Which natural disaster did you cause this time?', 'Hurricane', 'Wildfire', 'Tsunami', '1'] ['What is your theme song?', 'Ring of Fire by Johnny Cash', 'American Pie by Don McLean', 'Thunder by Imagine Dragons', '2'] ['How would you sink a ship?', 'I attacked it', 'I ran into it', 'It went BOOOOM! It was pretttty!', '3'] ]; var i=-1; var j=count=0; change(); function change() { i = i+1; j=0; question.innerHTML = quiz[i][j]; j = j + 1; button1.innerHTML = quiz[i][j]; j = j + 1; button2.innerHTML = quiz[i][j]; j = j + 1; button3.innerHTML = quiz[i][j]; j = j + 1; if(i>2){ alert("your score :"+count); return true; } else return false; }
function click1() { if(quiz[i][j] == 1) count = count + 1; return false; } function click2() { if(quiz[i][j] == 2) count = count + 1; return false; } function click3() { if(quiz[i][j] == 3) count = count + 1; return false; } |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started