diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..9f82f4110 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,81 @@ +`use strict` + +//returns current date and time +//create a function that inputs the year, month, and day +//make new var to store the today var and toDateString method +//use var today with toDateString method + +function dateDisplay(year, month, date) { + var today = new Date(year, month, date); + return today.toDateString(); +} + +dateDisplay(1985, 10, 1); + +//create a function with one argument. +//the argument should be a number +//return the argument with the toString() method to make the number a string + +function toNumber(number) { + return number.toString() +} + +toNumber(13); + +//create a fucntion that receives one argument +//argument should be a string +//use parseInt() method on argument to pull a number out + +function stringNum(str){ + return parseInt(str); +} + +stringNum('15 years'); + +//create a function with one argument +//use the typeOf method on the argument and return the result + +function dataType(dT){ + return typeof(dT); +} + +dataType(`words words words`); + +//Create a function with two arguments +//Inside the function, add the two var together +//Use parseInt() to take the number out of the string + +function add(numOne, numTwo) { + return parseInt(numOne) + parseInt(numTwo) +} + +add(`13`, `17`); + +//write a function that returns a true if two var are truthy +//if both var are true, show "nope" +//if both var are false, also show "nope" +// if one is false and one is true, show "yep!" + +function truest(thingOne, thingTwo) { + if ((thingOne === true && thingTwo === true) || (thingOne === false && thingTwo === false)){ + return `nope`; + } else { + return 'yep!'; + } +} + +truest(true, false); + +//write a function with two arguments +//if both arguments are false, show a confirmation message +//if either argument is true, return a negative response + +function womp(dumb, dumber) { + if (dumb === false && dumber === false) { + return `yes, they're both false` + } else { + return 'nah, try again' + } +}; + +womp(false, true); diff --git a/02week/pigLatin.js b/02week/pigLatin.js deleted file mode 100644 index 046434c94..000000000 --- a/02week/pigLatin.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const readline = require('readline'); -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - - -function pigLatin(word) { - - // Your code here - -} - - -function getPrompt() { - rl.question('word ', (answer) => { - console.log( pigLatin(answer) ); - getPrompt(); - }); -} - -// Tests - -if (typeof describe === 'function') { - - describe('#pigLatin()', () => { - it('should translate a simple word', () => { - assert.equal(pigLatin('car'), 'arcay'); - assert.equal(pigLatin('dog'), 'ogday'); - }); - it('should translate a complex word', () => { - assert.equal(pigLatin('create'), 'eatecray'); - assert.equal(pigLatin('valley'), 'alleyvay'); - }); - it('should attach "yay" if word begins with vowel', () => { - assert.equal(pigLatin('egg'), 'eggyay'); - assert.equal(pigLatin('emission'), 'emissionyay'); - }); - it('should lowercase and trim word before translation', () => { - assert.equal(pigLatin('HeLlO '), 'ellohay'); - assert.equal(pigLatin(' RoCkEt'), 'ocketray'); - }); - }); -} else { - - getPrompt(); - -} diff --git a/02week/tests.js b/02week/tests.js index e69de29bb..6991b4d89 100644 --- a/02week/tests.js +++ b/02week/tests.js @@ -0,0 +1,67 @@ +'use strict'; + +const assert = require('assert'); +const readline = require('readline'); +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + + +function rockPaperScissors(hand1, hand2) { + // check for a tie, if it is a tie, return tie, if not check for win + // rock beats scissors, scissors beats paper, paper beats rock + //to find who won, compare hand1 to hand2 + const handOne = 'Hand one wins!' + const handTwo = 'Hand two wins!' + + if(hand1 === hand2) { + return "It's a tie!"; + } else if (hand1 === 'rock'){ + return hand2 === 'paper' ? handTwo : handOne; + } else if (hand1 === 'paper') { + return hand2 === 'scissors' ? handTwo : handOne; + } else if (hand1 === 'scissors') { + return hand2 === 'rock' ? handTwo : handOne; + } +}; + +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('scissors', 'rock'), "Hand two wins!"); + assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!"); + assert.equal(rockPaperScissors('rock', 'scissors'), "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!"); + });w + // it('should detect ') + }); +} else { + + getPrompt(); + +} diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 40b9ebe92..ccfb90361 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -7,36 +7,69 @@ const rl = readline.createInterface({ output: process.stdout }); +//This is the initial setting at the beginning of towersOfHanoi. Part of premade code let stacks = { a: [4, 3, 2, 1], b: [], c: [] }; -function printStacks() { +//This function prints the stacks on to the screen. Part of premade code +let printStacks = () => { console.log("a: " + stacks.a); console.log("b: " + stacks.b); console.log("c: " + stacks.c); } -function movePiece() { - // Your code here - +//printBeginningStacks, reset the var stacks to its original position, nest stacks inside +const printBeginningStacks = (stacks) => { + stacks = { + a: [4, 3, 2, 1], + b: [], + c: [] + } + console.log('I want to play again, so we will.') } -function isLegal() { - // Your code here - +//movePiece(), Moves the last index of the startStack to the last index of the endStack, using pop and push +//using push, add the last value in your starting stack (using pop) to the end of your ending stack +const movePiece=(startStack, endStack)=> { + stacks[endStack].push(stacks[startStack].pop()); } -function checkForWin() { - // Your code here - +//isLegal(), checks to see if anything is in the first stack you choose. It then checks if the ending stack is empty. It then checks if the starting stack is smaller than the ending stack. If it meets all of those the move is legal +const isLegal = (startStack, endStack) => { + if (stacks[startStack].length === 0) { + console.log ('Please choose a stack with items in it! This move isn\'t legal!') + return false; + } else if( stacks[endStack].length === 0) { + return true; + } else if ((stacks[startStack].length - 1) > (stacks[endStack].length - 1)){ + return 'Not a legal move.'; + return false; + } else { + return true; + } } -function towersOfHanoi(startStack, endStack) { - // Your code here +//checkForWin, if all of the numbers are in the last stack, run the win sequence, which should reset the object, if statement +const checkForWin = () => { + if (stacks.c.length === 4) { + console.log("You win! Let's play again!"); + printBeginningStacks(stacks); + } else { + console.log('Keep trying, you\'ll get there!') + return false; + } +} +//towersOfHanoi, only needs to reference the isLegal function to get the list of finctions running +//if the move is legal, move the piece then check if you've won +const towersOfHanoi = (startStack, endStack) => { + if (isLegal(startStack, endStack)) { + movePiece(startStack, endStack); + checkForWin(); + } } function getPrompt() { @@ -50,5 +83,3 @@ function getPrompt() { } getPrompt(); - - diff --git a/04week/gitOlympics.js b/04week/gitOlympics.js new file mode 100644 index 000000000..332de72b7 --- /dev/null +++ b/04week/gitOlympics.js @@ -0,0 +1,9 @@ +'use strict' + +const names = ['athens', 'berlin', 'atlanta', 'seoul', 'los angeles'] + +const printListOfOlympics=(arr)=>{ + arr.forEach(i => console.log(i)) +} + +printListOfOlympics(names); diff --git a/index.html b/index.html index a8de93e90..ffe101bd4 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,6 @@ -

Hello World!

+

Hello Eric, how are you!

diff --git a/package-lock.json b/package-lock.json index 62353c45d..c6f9c9cc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3223,6 +3223,19 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node": { + "version": "8.9.1", + "resolved": "https://registry.npmjs.org/node/-/node-8.9.1.tgz", + "integrity": "sha512-Q+s+uYK6iNdsL91cHOPo1baugkdF6/m5zUbil4Ya9mMyfBnAn/J+htT5GniLIEsYRJ+mtBAWNR7XkePStXKFZQ==", + "requires": { + "node-bin-setup": "1.0.6" + } + }, + "node-bin-setup": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.0.6.tgz", + "integrity": "sha512-uPIxXNis1CRbv1DwqAxkgBk5NFV3s7cMN/Gf556jSw6jBvV7ca4F9lRL/8cALcZecRibeqU+5dFYqFFmzv5a0Q==" + }, "node-status-codes": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-status-codes/-/node-status-codes-1.0.0.tgz", diff --git a/package.json b/package.json index 5c6742f79..882713b6f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "functional-javascript-workshop": "^1.0.6", - "javascripting": "^2.6.1" + "javascripting": "^2.6.1", + "node": "^8.9.1" } }