Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secret word app and twice in a row and x in a row #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,71 @@
var numberOfWins = 0;
var numberOfWinsRequired = 0;

var main = function (input) {
var myOutputValue = 'hello world';
var secretWord = "";
numberOfWinsRequired = generateRandomNumber();
var secretNumber = generateThreeNumber();

if (secretNumber == 1) {
secretWord = "banana";
}
if (secretNumber == 2) {
secretWord = "chisel";
}
if (secretNumber == 3) {
secretWord = "faucet";
}
var myOutputValue =
"you lose! you guessed: " +
input +
", the secret word is: " +
secretWord +
", you need " +
(numberOfWinsRequired - numberOfWins) +
" number of wins";

if (input == secretWord) {
numberOfWins = numberOfWins + 1;
myOutputValue =
"you win. you guessed: " +
input +
", the secret word is: " +
secretWord +
" you need " +
(numberOfWinsRequired - numberOfWins) +
" number of wins";
}

if (input != secretWord) {
numberOfWins = 0;
myOutputValue =
"you lose! you guessed: " +
input +
", the secret word is: " +
secretWord +
", you need" +
numberOfWinsRequired +
"consecutive number of wins.";
}

return myOutputValue;
};

var generateThreeNumber = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
var threeNumber = randomInteger + 1;
return threeNumber;
};

var generateRandomNumber = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
var randomNumber = randomInteger + 2;
return randomNumber;
};
// please input "banana", "chisel" and "faucet"
// var random "banana", "chisel" and "faucet".
// condition to win - the player must guess correctly twice in total, e.g. the player still wins if she guesses wrongly 1 or more times between her 2 correct guesses.
// For each guess, output 1 ) guessed word, 2) secret word, 3) how many correct guesses the player still needs until she wins.
// Update Secret Word with an additional rule: The player must guess correctly twice in a row to win