I am new to programming in javascript, I cant figure out how to make my code to prompt the user for at least 3 times, prompt, then alert, again prompt, then alert, again prompt then alert… once 3 times the user fails to type something then a final alert shows up like “No more attempts!” and the DIV turns grey color, could some someone help me?
Javascript:
var mObjt = {
userInput: "",
setInput: function(){
document.getElementById("div1").innerHTML = mObjt.userInput;},
conRequest: function(){
if(mObjt.userInput != ""){
mObjt.setInput();}
else{
alert("There is no input!");
mObjt.popRequest();}},
popRequest: function(){
mObjt.userInput = prompt("Enter a word:");
mObjt.conRequest();}
HTML:
< div id="div1" style="width:200px; height:30px; border:1px solid;">< /div>
< button type="button" onClick="mObjt.popRequest()">Add Input</ button>