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

Updated Secret Word program #48

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
56 changes: 56 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
/*
---REQUIREMENTS---
[x] Program randomly chooses secret word from set of 3 words: "banana", "chisel" and "faucet"
[x] Win condition == user guessing secret word twice in total
[x] user input the correct word from the 3 words
[x] counter that tracks user wins
[x] Each guess output all information
*/

var playerWins = 0;
var requiredWins = 2;

var main = function (input) {
var myOutputValue = 'hello world';
var playerChoice = input;
console.log(playerChoice);

if (
playerChoice !== "banana" ||
playerChoice !== "chisel" ||
playerChoice !== "faucet"
) {
myOutputValue =
"Wrong input detected, please enter 'banana', 'chisel' or 'faucet'!";
};

var computerChoice = secretWord();
console.log(computerChoice);

if (playerChoice == computerChoice) {
playerWins += 1;
console.log(playerWins);
myOutputValue = `You guessed ${playerChoice}, the secret word is ${computerChoice}. You currently have ${playerWins} wins, you need ${
requiredWins - playerWins
} more wins for victory!`;
if (playerWins == requiredWins) {
myOutputValue = `You guessed ${playerChoice}, the secret word is ${computerChoice}. You currently have ${playerWins} wins, you achieved ${requiredWins} wins. Victory!!!`;
};
} else {
console.log(playerWins);
myOutputValue = `You guessed ${playerChoice}, the secret word is ${computerChoice}. You currently have ${playerWins} wins, you need ${
requiredWins - playerWins} more wins for victory`;
};

return myOutputValue;
};



var secretWord = function() {
var randomNumber = Math.floor(Math.random() * 3) + 1;

if (randomNumber == 1) {
return "banana"
} else if (randomNumber == 2) {
return "chisel"
} else if (randomNumber == 3) {
return "faucet"
};
};