| 24 | } |
| 25 | |
| 26 | function nextQues(){ |
| 27 | |
| 28 | if(document.querySelector("#answerBox")){ |
| 29 | document.querySelector("#answerBox").innerHTML=""; |
| 30 | } |
| 31 | if (document.querySelector("#questionBox")) { |
| 32 | document.querySelector("#questionBox").innerHTML = ""; |
| 33 | } |
| 34 | if (document.querySelector("#warning")) { |
| 35 | document.querySelector("#warning").innerHTML = ""; |
| 36 | } |
| 37 | |
| 38 | document.querySelector("#userInput").value=null; |
| 39 | |
| 40 | |
| 41 | var operators=["+","-","*","/"]; |
| 42 | |
| 43 | var randomOperand1=Math.floor(Math.random()*100); |
| 44 | var randomOperand2=Math.floor(Math.random()*100); |
| 45 | var randomOperator= operators[Math.floor(Math.random()*operators.length)]; |
| 46 | |
| 47 | switch (randomOperator) { |
| 48 | case "+": |
| 49 | res = randomOperand1 + randomOperand2; |
| 50 | break; |
| 51 | case "-": |
| 52 | res = randomOperand1 - randomOperand2; |
| 53 | break; |
| 54 | case "*": |
| 55 | res = randomOperand1 * randomOperand2; |
| 56 | break; |
| 57 | case "/": |
| 58 | res = randomOperand1 / randomOperand2; |
| 59 | break; |
| 60 | } |
| 61 | var isFloat = Number.isInteger(res) ? false : true ; |
| 62 | if(isFloat){ |
| 63 | res=res.toFixed(2); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | var quesBoxValue=document.querySelector("#questionBox"); |
| 68 | quesBoxValue.innerHTML="What is ".concat(randomOperand1 ,randomOperator ,randomOperand2 ,"?"); |
| 69 | quesBoxValue.style.color="blue"; |
| 70 | } |
| 71 | |
| 72 | function viewAnswer(){ |
| 73 | if (!document.querySelector("#userInput").value) { |