About JavaScript Math.random(); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

About JavaScript Math.random();

Anyone to please help me on how to write this code. i tried it but just a second opinion so i compare. Write a program that will generate 2 RANDOM numbers and display them, request user to enter the sum, of the two numbers , if the answer is correct , program should display correct answer, if answer entered is wrong ,program should display wrong answer then display the correct answer. please explain with some comments like you explain to a beginner so i understand.

16th Jul 2020, 7:04 AM
Memory Tshaawane
Memory Tshaawane - avatar
2 Answers
+ 8
For a random number between 0 and 1: Math.random(); Rn between 0 and 10: Math.random()*10; 2 variables with random values: var a = Math.floor(Math.random()*10); var b = Math.floor(Math.random()*10); //then you display them on the screen. //ask the user for the numbers sum (using prompt(), html element or whatever you want //use a if and else statement to write correct or wrong answer.
16th Jul 2020, 7:10 AM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
0
THANK YOU
16th Jul 2020, 11:50 AM
Memory Tshaawane
Memory Tshaawane - avatar