I would like to have a text field that a user can enter a number and if the number is correct it the displays “image a” and if incorrect displays “image b” below the text field i want them to have as many tries as they like to get it correct. The only thing i have found so far is this?
sorry about the lack of experience guys 🙁
var my_string = prompt("Please enter a number","");
document.write(my_string)
if(isNaN(my_string)){
document.write ("this is not a number ");
}else{document.write ("this is a number ");
}
The user will enter characters, so you’ll have to compare strings. You can use the
===operator which checks equality; you’ll have to check against the string"25".Then, to display the image, you’ll have to give the images in HTML an ID. After doing so, you can fetch the element in JavaScript using
document.getElementById("some_id"). Showing/hiding is done usingelement.style.display = "block"vs"none".