Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. function random(max) {
  2. return Math.floor(Math.random() * Math.floor(max));
  3. }
  4. function start() {
  5. var form = document.getElementById("name_form");
  6. var name = form.elements[0].value;
  7. var score = 0;
  8. alert("Let's begin!");
  9. for (let i = 0; i < 4; i++) {
  10. var num1 = random(10);
  11. var num2 = random(10);
  12. var operator = random(2);
  13. if (operator == 0) {
  14. var question = prompt(num1 + " + " + num2 + " =");
  15. var answer = num1 + num2;
  16. }
  17. else {
  18. var question = prompt(num1 + " - " + num2 = " =");
  19. var answer = num1 - num2;
  20. }
  21. if (question == answer) {
  22. alert("Correct!");
  23. score++;
  24. }
  25. else {
  26. alert("Incorrect ):");
  27. }
  28. }
  29. document.write(score);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement