I wanna make a simple app ..could somone help plz? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I wanna make a simple app ..could somone help plz?

i wanna make an app that gives me a prompt("enter a number>0") and when i enter a number<0 (a wrong answer) the code just give me that prompt("try again"), and if i answerd wrong for any number of times it just give me this prompt("try again"), what should i do?

14th Dec 2016, 10:57 PM
Hazem Ahmed
Hazem Ahmed - avatar
4 Answers
+ 3
Try this : window.onload = function main() { var num = prompt("Enter a number > 0") ; // Takes input from user if (num > 0) { alert("Good job!") ; } // If the number is > 0, alert pops up else { error() ; } // If no, this function is executed } // Below is the function function error() { var num2 = prompt("Number must be greater than 0!") ; if (num2 > 0) { alert("Good job!") ; } else { error() ; } // Recursive function }
16th Dec 2016, 7:38 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
Use HTML form where action method connected to OnClick should check the given value if its correct and if not, just display prompt on active screen.
15th Dec 2016, 1:46 AM
Maksym Zieliński
Maksym Zieliński - avatar
0
while loop would be good here to allow you to enter until an exit condition is met allowing the user to try different values without having to restart your program
14th Dec 2016, 11:44 PM
Cory Clapp
Cory Clapp - avatar
- 1
I know a little of java no js if(x<=0){ Show message } else{ Continue }
14th Dec 2016, 11:03 PM
Jose Luis Flores Aguirre
Jose Luis Flores Aguirre - avatar