Here’s the code I wrote for the ‘numbers’ function. This is another simple function to obtain input from the user.The only thing needed if to verify that the input is within range and that that value is passed back out of the function:
//function to get numerals to be used in code
var numbers = function(){
var enteredNumber = 0;
var numbersVeritas = false;
while (numbersVeritas === false){
console.log(“***numbers function reached***”);
//player inputs how many digits the code will be
// so far numbers function works fine
enteredNumber = prompt(“code will consist of numerals 1 – : (1-9)”);
if (enteredNumber>0 && enteredNumber <=9){
console.log(“We will be using numerals from 1 to “+ enteredNumber+ ” for our code”);
numbersVeritas = true;
return enteredNumber;
} else{
alert(“number is out of range.”);
numbersVeritas = false;
}
}
};
//function call
var enteredNumber = numbers(); // brings the variable enteredNumber out of the function
console.log(enteredNumber); // used to verify enteredNumber is passed back from function