+ 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?
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
}
+ 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.
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
- 1
I know a little of java no js
if(x<=0){
Show message
}
else{
Continue
}