RSS

Function to get numeral range for code

30 Jun

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

Advertisements
 
Leave a comment

Posted by on June 30, 2012 in Uncategorized

 

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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: