0% found this document useful (0 votes)
26 views

Forbidden Number Game Program Code

Uploaded by

syed.yousuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Forbidden Number Game Program Code

Uploaded by

syed.yousuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

//List including numbers 1-100 which will be used to generate the forbidden numbers as well as remove the

target number to avoid overlapping


var numberList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100];

//Chooses a random number to be the target number


//from 1-100 and deletes that number from numberList.
var target = randomNumber(1, 100);
removeItem(numberList, target - 1);

//creates forbiddenList and variable for forbiddenNumber to determine forbidden numbers.


var forbiddenList = [0];
var forbiddenNumber;
//Calls the result function each time a different number is chosen from the dropdown.
onEvent("dropdown", "change", function( ) {
result();
});

//chosenNumber is taken from the user's selection from


//the dropdown list, which then goes through a loop
//to check whether it is in the forbidden list or not.
//If it is, then it is classified as forbiddenNumber,
//and the result is returned accordingly.
function number(chosenNumber) {
chosenNumber = getNumber("dropdown");
for (var i = 0; i < forbiddenList.length; i++) {
if (chosenNumber == forbiddenList[i]) {
chosenNumber = forbiddenNumber;
}
}
return chosenNumber;
}

//The number generated by the "number" function into the variable "u"
//which goes through a series of conditions to determine whether
//it is the target number, a forbidden number, or neither.
//If it is the target number, the player wins.
//If it is a forbidden number, the player loses.
//If it is neither, the player is prompted to try again and
//a random number from "numberList" is appended into the forbidden numbers list.
function result() {
var u = number(u);
if (u == target) {
setText("result", "Correct");
setProperty("result", "text-color", rgb(223, 154, 105));
setProperty("result", "text-align", "center");
} else if ((u == forbiddenNumber)) {
setText("result", "FORBIDDEN NUMBER!!");
setProperty("result", "text-align", "center");
setProperty("result", "text-color", rgb(96, 40, 19));
setProperty("dropdown", "hidden", true);
} else if ((u != target)) {
setText("result", "Try Again");
setProperty("result", "text-align", "center");
setProperty("result", "text-align", "center");
setProperty("result", "text-align", "center");
setProperty("result", "text-color", rgb(251, 239, 180));
appendItem(forbiddenList, numberList[(randomNumber(0, numberList.length - 1))]);
}
}

You might also like