Skip to content
Open
Show file tree
Hide file tree
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
Empty file removed 01week/datatypes.js
Empty file.
45 changes: 43 additions & 2 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,52 @@ const rl = readline.createInterface({
output: process.stdout
});

// hand1 enters move, hand2 move (done for us)
// check to see if move is valid. checkValid
// if moves invalid redo moves (getprompt)
// check win state (loss or tie). checkWin()

function rockPaperScissors(hand1, hand2) {
if (checkValid(hand1) && checkValid(hand2)) {
if (hand1 == hand2) {
return "It's a tie!";
}
// hand1 = rock
else if (hand1 == "rock") {
if (hand2 == "scissors") {
return "Hand one wins!";
} else {
return "Hand two wins!";
};
}
// hand1 = paper
else if (hand1 == "paper") {
if (hand2 == "rock") {
return "Hand one wins!";
} else {
return "Hand two wins!";
};
}
// hand1 = scissors
else if (hand1 == "scissors") {
if (hand2 == "paper") {
return "Hand one wins!";
} else {
return "Hand two wins!";
}
}
} else {
console.log('Please redo');
}
}

// Write code here

const checkValid = (hand) => {
const lowerCase = hand.toLowerCase()
if (lowerCase == 'rock' || lowerCase == 'paper' || lowerCase == 'scissors') {
return true;
} else {
return false;
}
}

function getPrompt() {
Expand Down