RSS

function#1: User provides number of digits in the secret code

29 Jun

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.”);
            
        }
    }

};

 

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: