I am new to JavaScript and decided to create my own JS quiz.
Here's what I have so far:
<script type="text/javascript">
score = 0;
var questions = [['whats 2 + 2' , '4'] , ['whats 3 * 3' , 9] , ['whats 2 * 7' , 14] ];
function askQ(ans){
var answer =prompt (questions[i] , '');
if(answer == questions[1]){
score++;
alert('Yahooo , ur right');
} else{
alert('Brush up ur GK');
}
}
for (var i = 0; i < questions.length ; i++) {
askQ(questions[i]);
};
</script>
The problem is when the question "prompted" to the users screen, the answer is also displayed simultaneousl , eg . for the 1st question this is what appears:
"what is 2+2,4" .. now you see , "4" is the answer
I am sure in order for the 4 not to display I need to do something differently, so I went through a few online snippets of code and it was either too complex for me to understand.
Here is a jsfiddle.
questions[i]is an array consisting of two elements. you want to displayquestions[i][0]in the prompt, and compare the answer toquestions[i][1].