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
13 changes: 9 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<div id="display-element"></div>
<button onclick="displayDate()">Click Me</button>
<hr/>
<form>
Rock, Paper, or Scissors (use R, P, or S): <input type="text" name="FirstName" id="rpc"><br>
Rock, Paper, or Scissors (use R, P, or S): <input type="text" name="LastName" id="rpcTwo"><br>
<hr>
<button onclick="rockPaperScissors(getElementById('rpc').value, getElementById('rpcTwo').value)
">Result</button>
<p id="final"></p>
</form>

</body>
</html>
220 changes: 165 additions & 55 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,172 @@
// uses strict mode so strings are not coerced, variables are not hoisted, etc...
'use strict';

// brings in the assert module for unit testing
const assert = require('assert');
// brings in the readline module to access the command line
const readline = require('readline');
// use the readline module to print out to the command line
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

// the function that will be called by the unit test below
const rockPaperScissors = (hand1, hand2) => {
// const letter = ["R", "P", "S"]
// const randomIndex = letter[Math.floor(Math.random() * letter.length)];
// console.log(randomIndex);

// Write code here
// Use the unit test to see what is expected
// const letterTwo = ["R", "P", "S"]
// const randomIndexTwo = letterTwo[Math.floor(Math.random() * letterTwo.length)];
// console.log(randomIndexTwo);
// // the function that will be called by the unit test below

}

// the first function called in the program to get an input from the user
// to run the function use the command: node main.js
// to close it ctrl + C
function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
console.log( rockPaperScissors(answer1, answer2) );
getPrompt();
});
});


// const answer = ""

document.getElementById("rpc").onclick, document.getElementById("rpcTwo").onclick = rockPaperScissors (hand1, hand2) => {

if (hand1 === hand2) {
// answer = 'Its a tie'
return 'Its a tie'
document.getElementById("final").innerHTML = 'Its a tie!'
}
else if (hand1 === "S" && hand2 === "P") {
// answer = 'Its a tie'
return 'Player 1 wins!'
}
else if (hand1 === "S" && hand2 === "R") {
// answer = 'Its a tie'
return 'Player 2 wins!'
}
else if (hand1 === "P" && hand2 === "R") {
// answer = 'Its a tie'
return 'Player 1 wins!'
}
else if (hand1 === "P" && hand2 === "S") {
// answer = 'Its a tie'
return 'Player 2 wins!'
}
else if (hand1 === "R" && hand2 === "P") {
// answer = 'Its a tie'
return 'Player 2 wins!'
}
else if (hand1 === "R" && hand2 === "S") {
// answer = 'Its a tie'
return 'Player 1 wins!'
}
else {
return 'Something went wrong!'
}

}

// Unit Tests
// You use them run the command: npm test main.js
// to close them ctrl + C
if (typeof describe === 'function') {

// most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built return the expected output.
describe('#rockPaperScissors()', () => {
it('should detect a tie', () => {
assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!");
assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!");
assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!");
});
it('should detect which hand won', () => {
assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
});
it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!");
assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!");
assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!");
});
});
} else {

// always returns ask the user for another input
getPrompt();
const answer = ""

const rockPaperScissors = (hand1, hand2) => {
if (hand1 === hand2) {
answer = 'Its a tie'
return answer
}
else if (hand1 === "S" && hand2 === "P") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "S" && hand2 === "R") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "P" && hand2 === "R") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "P" && hand2 === "S") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "R" && hand2 === "P") {
answer = 'Its a tie'
return answer
}
else if (hand1 === "R" && hand2 === "S") {
answer = 'Its a tie'
return answer
}
else {
return 'Something went wrong!'
}

}
rockPaperScissors(randomIndex, randomIndexTwo)






















// // uses strict mode so strings are not coerced, variables are not hoisted, etc...
// 'use strict';

// // brings in the assert module for unit testing
// const assert = require('assert');
// // brings in the readline module to access the command line
// const readline = require('readline');
// // use the readline module to print out to the command line
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });

// // the function that will be called by the unit test below
// const rockPaperScissors = (hand1, hand2) => {

// // Write code here
// // Use the unit test to see what is expected

// }

// // the first function called in the program to get an input from the user
// // to run the function use the command: node main.js
// // to close it ctrl + C
// function getPrompt() {
// rl.question('hand1: ', (answer1) => {
// rl.question('hand2: ', (answer2) => {
// console.log( rockPaperScissors(answer1, answer2) );
// getPrompt();
// });
// });
// }

// // Unit Tests
// // You use them run the command: npm test main.js
// // to close them ctrl + C
// if (typeof describe === 'function') {

// // most are notes for human eyes to read, but essentially passes in inputs then compares if the function you built return the expected output.
// describe('#rockPaperScissors()', () => {
// it('should detect a tie', () => {
// assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!");
// assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!");
// assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!");
// });
// it('should detect which hand won', () => {
// assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
// assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
// assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
// });
// it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
// assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!");
// assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!");
// assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!");
// });
// });
// } else {

// // always returns ask the user for another input
// getPrompt();

// }