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
29 changes: 27 additions & 2 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,32 @@ const rl = readline.createInterface({

function rockPaperScissors(hand1, hand2) {

// Write code here

// Rock paper Scissors function, below:

if (hand1 === hand2){
console.log("It's a tie.")
};
if (hand1 === 'rock' && hand2 === 'scissor') {
console.log("User1 wins.")
};
if (hand1 ==='rock'&& hand2 === 'paper'){
console.log("User2 wins.")
};
if (hand1 === 'paper'&& hand2 === 'rock') {
console.log("User1 wins.")
};
if (hand1 === 'paper' && hand2 === 'scissors'){
console.log("User2 wins.")
};
if (hand1 === 'scissors' && hand2 === 'paper'){
console.log("User1 wins.")
};
if (hand1 === 'scissors'&& hand2 === 'rock'){
console.log("User2 wins.")
};
}
rockPaperScissors("rock","paper");


function getPrompt() {
rl.question('hand1: ', (answer1) => {
Expand Down Expand Up @@ -48,4 +71,6 @@ if (typeof describe === 'function') {

getPrompt();



}
8 changes: 6 additions & 2 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ const rl = readline.createInterface({
output: process.stdout
});

//added pigLatin code

function pigLatin(word) {

// Your code here

}
word= word.toLowerCase();
let vowels = word.search(/[aeiuo]/);
console.log(word.substring(vowels) + word.substring(0,vowels) + "ay")
}
pigLatin("car");


function getPrompt() {
Expand Down
41 changes: 41 additions & 0 deletions 02week/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
if (typeof describe === 'function') {

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('scissors', 'rock'), "Hand two wins!");
assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
assert.equal(rockPaperScissors('scissors','paper'), "Hand one wins!");
assert.equal(rockPaperScissors('paper', 'rock'), "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!");
});

it('should detect if input is valid', () =>{
assert.equal(rockPaperScissors('cat', ' 3 '), "Invalid Entry");
assert.equal(rockPaperScissors('rock', ' Cat '), "Invalid Entry");
assert.equal(rockPaperScissors('', ''), "Invalid Entry");
assert.equal(rockPaperScissors('#', 'rock'), "Invalid Entry");
assert.equal(rockPaperScissors('=', 'paper!'), "Invalid Entry");
assert.equal(rockPaperScissors('rock2', 'rock?'), "Invalid Entry");


})
});
} else {

getPrompt();

}



55 changes: 55 additions & 0 deletions 03week/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// week 3 array exercises:

//length
let cars = ["Ford","Chevy","Dodge","Toyota"];
console.log(cars.length);

//concat
let moreCars = ["Subaru","Mazda","Bmw","Honda"];
let totalCars = cars.concat(moreCars);
console.log(totalCars);

//indexOf/lastIndexOf:
console.log(moreCars.indexOf("Honda"))
console.log(cars.lastIndexOf("Ford"));

//join
let stringOfCars = totalCars.join();
console.log(stringOfCars);

//split
console.log(stringOfCars.split());

//reverse
let carsInReverse = totalCars.reverse();
console.log(carsInReverse);

//sort,
console.log(carsInReverse.sort());
//slice
let removedCars = carsInReverse.slice(3,5);
console.log(removedCars);

//splice
console.log("my new array: " + carsInReverse.splice(1, 5, "Ford", "Honda"));
console.log(carsInReverse);

//push
console.log(carsInReverse.push("Dodge", "Mazda"));
console.log(carsInReverse);

//pop
console.log(carsInReverse.pop());

//shift
console.log(carsInReverse.shift());

//unshift
console.log(carsInReverse.unshift("Jeep"));
console.log(carsInReverse);

//forEach
let numbers = [23, 45, 0, 2];
numbers.forEach(function(number) {
console.log(number + 2);
})
Loading