Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function random(max) {
- return Math.floor(Math.random() * Math.floor(max));
- }
- function start() {
- var form = document.getElementById("name_form");
- var name = form.elements[0].value;
- var score = 0;
- alert("Let's begin!");
- for (let i = 0; i < 4; i++) {
- var num1 = random(10);
- var num2 = random(10);
- var operator = random(2);
- if (operator == 0) {
- var question = prompt(num1 + " + " + num2 + " =");
- var answer = num1 + num2;
- }
- else {
- var question = prompt(num1 + " - " + num2 = " =");
- var answer = num1 - num2;
- }
- if (question == answer) {
- alert("Correct!");
- score++;
- }
- else {
- alert("Incorrect ):");
- }
- }
- document.write(score);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement