Here’s my first function.
It prompts the user to provide a number of digits from 1-6. It then confirms this with the user – well, really just me for debugging purposes. I also use a Boolean ‘codeVeritas’ to ensure that the number of digits the user enters is within the parameters defined.
//gets the number of digits used
var code = function(){
var enteredCode = 0;
var codeVeritas = false;
//so far the codeVeritas is working fine
while (codeVeritas === false){
console.log(“***code function reached***”);
enteredCode = prompt(“How many digits shall the code be? (1-6)”);
//verify input
if (enteredCode > 0 && enteredCode <= 6){
console.log(“We will be using “+ enteredCode+ ” digits in our code”);
codeVeritas = true;
return enteredCode;
} else{
alert(“number is out of range.”);
}
}};