/    Sign up×
Community /Pin to ProfileBookmark

please help with a function

here’s the whole script. there seems to be a problem in the first if-then statement of the function, because it always says that you get 0 correct. i call upon this with quiz(rageQuestion, rageAnswer) or quiz(f50Question, f50Answer), or, you get the point. just say so if the attached file would be helpful. if someone would please take the time to point out my error it would be greatly appreciated.


————————————————————

var rageQuestion = new Array(“In what year was Rage Against the Machine’s album ‘The Battle of Los Angeles’ released?”, “How many band members were in Rage Against the Machine?”,
“Tom Morello plays what instrument?”);
var rageAnswer = new Array(“1999”, “4”, “guitar”);

var f50Question = new Array(“What is the Ferrari F-50’s top speed? (in mph)”, “In what year was the F-50 made?”,
“How much horsepower does a Ferrari F-50 have?”);
var f50Answer = new Array(“202”, “1995”, “520”);

var chimpQuestion = new Array(“On which continent do chimpanzees live in the wild?”, “True or false – in the United States, over 1400 chimps are used for biomedical research”,
“To the nearest one hundredth, what percent chimpanzees are genetically identical to humans?”);
var chimpAnswer = new Array(“africa”, “true”, “98.76”);

var steadyQ = new Array();
var correct=0;
var response=new Array(” Better luck next time!”, ” At least you got one!”, ” Not bad!”, ” You know a lot!”);

function quiz(question, answer, tried)
{
for(var loop=0; loop<3; loop++)
{
steadyQ = prompt(question[loop], “”);
if(steadyQ[loop]==answer[loop])
{
correct++;
}
}
alert(“You got ” + correct + ” correct! ” + response[correct]);
if(correct!=3)
{
var answerKey=confirm(“Do you want to view the correct answers?”);
if(answerKey==1)
{
for(var looper=0; looper<3; looper++)
{
alert(answer[looper]);
}
}
}
}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ray326Jan 18.2004 — steadyQ = prompt(question[loop], "");

should be

steadyQ[loop] = prompt(question[loop], "");
×

Success!

Help @guitrage spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...