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
46 changes: 46 additions & 0 deletions 02week/exercises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// length
let cars = ['Ford', 'BMW', 'Audi', 'Toyota'];
console.log(cars.length);

// conat
let moreCars = ['Buick', 'Mercedes', 'Lexus', "Honda"];
let totalCars = cars.concat(moreCars);
console.log(totalCars);
// cant figure out how to rename the new array

// indexOf and lastIndexOf
console.log(totalCars.indexOf('Honda'));
console.log(totalCars.lastIndexOf('Ford'));

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

// split
totalCars = stringOfCars.split(" ");
console.log(totalCars);

// reverse
carsInReverse = totalCars.reverse();
console.log(carsInReverse);
// cant get this one to reverse. still prints items in order

// sort
carsInReverse.sort();
console.log(carsInReverse);
// alert(carsInReverse.indexOf('Audi'));
// not working

// slice

// splice

// push

// pop

// shift

// unshift

// forEach
86 changes: 86 additions & 0 deletions 02week/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});



function rockPaperScissors(hand1, hand2) {
if (hand1 === hand2) {
return "It's a tie!"
}
if (hand1 === 'rock' && hand2 === 'paper') {
return "Hand2 wins!"
}
if (hand1 === 'rock' && hand2 === 'scissors') {
return "Hand1 wins!"
}
if (hand1 === 'paper' && hand2 === 'scissors') {
return "Hand2 wins!"
}
if (hand1 === 'paper' && hand2 === 'rock') {
return "Hand1 wins!"
}
if (hand1 === 'scissors' && hand2 === 'paper') {
return "Hand1 wins!"
}
if (hand1 === 'scissors' && hand2 === 'rock') {
return "Hand2 wins!"
}
};



function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
console.log(rockPaperScissors(answer1, answer2));
getPrompt();
});
});
}




// Tests

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('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!");
});
// my tests for checking which hand is the winner
it('should detect if hand1 won', () => {
assert.equal(rockPaperScissors('paper', 'rock'), "Hand one wins!");
assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!");
});
it('should detect if hand2 won', () => {
assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!");
assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
});
});
} else {

getPrompt();

}