-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1011 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function generateRandom(){
return Math.floor(Math.random() * (100 * Math.random()));
}
var number1;
var number2;
var answer;
var button = document.querySelector(".quiz-submit");
function game(){
document.querySelector(".quiz-input").value = "";
number1 = generateRandom();
number2 = generateRandom();
answer = number1 + number2;
var question = "";
question = number1 + " + " + number2;
document.querySelector(".quiz-question").innerText = question;
}
game();
button.addEventListener("click", function(){
var userInput = parseInt(document.querySelector(".quiz-input").value);
// console.log(answer);
// console.log(userInput);
if(userInput === answer){
console.log("correct");
correct();
game();
}
else{
console.log("wrong");
wrong();
game();
}
})
function correct(){
window.location.href = "success-page/success.html";
}
function wrong(){
window.location.href = "fail-page/fail.html";
}