diff --git a/03week/towersOfHanoi.js b/03week/towersOfHanoi.js index 3cf6df049..02e93129f 100644 --- a/03week/towersOfHanoi.js +++ b/03week/towersOfHanoi.js @@ -19,24 +19,45 @@ function printStacks() { console.log("c: " + stacks.c); } -function movePiece() { - // Your code here +function movePiece(startStack,endStack) { + // console.log(start) + // console.log(end) + let disc = stacks[startStack].pop(); + // console.log(disc) + stacks[endStack].push(disc); } -function isLegal() { - // Your code here +function isLegal(startStack,endStack) { + let start = stacks[startStack]; + let end = stacks[endStack]; + let startDisc = start[start.length-1]; + let endDisc = end[end.length-1]; + // console.log(startDisc,endDisc) + if(start.length == 0 ){ + return false; + }else if((startDisc < endDisc) ||(end.length == 0)){ + return true; + }else{ + console.log('invalid, did nothing') + return false; + + } + } function checkForWin() { - // Your code here - + if (stacks.b.length === 4 || stacks.c.length === 4){ + console.log('win!') + return true; + }else { + return false; + } } function towersOfHanoi(startStack, endStack) { - // Your code here - + movePiece(startStack,endStack); } function getPrompt() { diff --git a/04week/loop.js b/04week/loop.js index e69de29bb..07933e911 100644 --- a/04week/loop.js +++ b/04week/loop.js @@ -0,0 +1,68 @@ + // Use a do...while loop to console.log the numbers from 1 to 1000. +let result = [,]; +let i = 0; + +do { + i = i + 1; + result = result + i; +} while (i <= 999); +console.log(result); + + // Create an object (an array with keys and values) called person with the following data: +let person = { + firstName: "Jane", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female" +} + + // Use a for...in loop and if statement to console.log + //the value associated with the key birthDate if the birth year is an odd number. +for(birthDate in person){ + if(birthDate % 2 !== 0){ + console.log(person.birthDate); + }; +} + + // Create an arrayOfPersons that contains multiple objects. + //You can simply copy/paste the person object you made above multiple times. + //Feel free to change the values to reflect multiple people you might have in your database. +arrayOfPersons = [ + { + firstName: "Jane", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female" + }, + { + firstName: "Bob", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female" + }, + { + firstName: "Steve", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female" + }, + { + firstName: "Marcus", + lastName: "Doe", + birthDate: "Jan 5, 1925", + gender: "female" + }, +] + + // Use .map() to map over the arrayOfPersons and console.log() their information. +let info = arrayOfPersons.map(arrayOfPersons); +console.log(info); + + // Use .filter() to filter the persons array and console.log only males in the array. +const males = arrayOfPersons.filter(arrayOfPersons.gender !="female"); +console.log(males); + + // Use .filter() to filter the persons array and console.log only people that were born before Jan 1, 1990. +const thirty = arrayOfPersons.filter(arrayOfPersons.birthDate < "Jan 1, 1990"); +console.log(thirty); + \ No newline at end of file diff --git a/04week/mastermind.js b/04week/mastermind.js index 60e5cfa18..12a881162 100644 --- a/04week/mastermind.js +++ b/04week/mastermind.js @@ -8,7 +8,7 @@ const rl = readline.createInterface({ }); let board = []; -let solution = ''; +let solution =['abcd']; let letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; function printBoard() { @@ -17,31 +17,56 @@ function printBoard() { } } -function generateSolution() { - for (let i = 0; i < 4; i++) { - const randomIndex = getRandomInt(0, letters.length); - solution += letters[randomIndex]; - } -} +// function generateSolution() { //creates the randomized solution +// for (let i = 0; i < 4; i++) { +// const randomIndex = getRandomInt(0, letters.length); +// solution += letters[randomIndex]; +// } +// } + +// function getRandomInt(min, max) { //creates rando interger to use in generate soln? +// return Math.floor(Math.random() * (max - min)) + min; +// } -function getRandomInt(min, max) { - return Math.floor(Math.random() * (max - min)) + min; -} -function generateHint() { - // your code here +function generateHint(guess) { + let countExact = 0; + let countLetter = 0; + // could i have used: for (let i of guess){} ? // + for (let i= 0; i<= guess.length; i++) { + for (let j= 0; j< 4; j++) {//for each [i] of array, compare every [j] of array + if(guess[i] == solution[i]){ //for exact match + countExact ++; //add to count + solution[i] = 'null';//take it off soln [] so it won't be double counted + //add to board [] <- has all the exact matches //<- the test seems to use board.length for hints? + + + }else if(guess[i] == solution[j]){//for letter only match + countLetter++; //add to count + solution[j] = 'null';//take off solution + // board.push(solution[j]);//add to board [] <- now has all the exact & letter only matches, including doubles, in order:exact,letter + }; + return `${countExact} - ${countLetter}`; + }; + }; } -function mastermind(guess) { - solution = 'abcd'; // Comment this out to generate a random solution - // your code here + +function mastermind(guess) { + // console.log(solution); + if(guess === solution){ + console.log('You guessed it!'); + }else{ + generateHint(guess); + } + } function getPrompt() { + printBoard(); rl.question('guess: ', (guess) => { mastermind(guess); - printBoard(); getPrompt(); }); } @@ -72,6 +97,6 @@ if (typeof describe === 'function') { } else { - generateSolution(); + // generateSolution(); getPrompt(); } diff --git a/06week/hangman.css b/06week/hangman.css new file mode 100644 index 000000000..242eac8cd --- /dev/null +++ b/06week/hangman.css @@ -0,0 +1,171 @@ +/* general */ +body { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; +} +/* +/* create a stick figure */ +.person { + position: relative; + margin: 1 auto; + width: 150px; + height: 350px; + text-align: center; +} +.person > div { + margin: 1 auto; + position: absolute; +} +.person > div.center { + margin: 1 auto; + left: 50%; + transform: translateX(-50%); +} +.person .head { + height: 50px; + width: 50px; + border: solid 1px #000; + border-radius: 50%; +} +.person .torso { + width: 1px; + height: 85px; + background: #000; + top: 51px; +} +.person .arm { + width: 1px; + height: 35px; + background: #000; + top: 55px; +} +.person .arm.left { + left: calc(50% - 1px); + transform-origin: bottom; + transform: rotate(-45deg); + animation-name: wave; + animation-duration: 10s; + animation-iteration-count: infinite; +} +.person .arm.right { + left: calc(50% - 1px); + transform-origin: bottom; + transform: rotate(45deg); +} +.person .leg { + width: 1px; + height: 50px; + background: #000; + top: 85px; +} +.person .leg.left { + left: calc(50% - 1px); + transform-origin: bottom; + transform: rotate(-145deg); +} +.person .leg.right { + left: calc(50%); + transform-origin: bottom; + transform: rotate(145deg); +} + +@keyframes wave { + 0% { + transform-origin: bottom; + transform: rotate(-45deg); + } + 10% { + transform-origin: bottom; + transform: rotate(-75deg); + } + 20% { + transform-origin: bottom; + transform: rotate(-45deg); + } +} + +/* .person { + position: relative; + margin: 0 auto; + width: 150px; + height: 350px; + text-align: center; +} +.head-center { + left: 50%; + transform: translateX(-50%); +} + +.head { + height: 50px; + width: 50px; + border: solid 1px #000; + border-radius: 50%; +} + +.torso-center { + width: 1px; + height: 85px; + background: #000; + top: 51px; +} + +.arm-left{ + width: 1px; + height: 35px; + background: #000; + top: 55px; + left: calc(50% - 1px); + transform-origin: bottom; + transform: rotate(-45deg); + animation-name: wave; + animation-duration: 10s; + animation-iteration-count: infinite; + } +.arm-right{ + width: 1px; + height: 35px; + background: #000; + top: 55px; + left: calc(50% - 1px); + transform-origin: bottom; + transform: rotate(45deg); + } + +.leg-left { + width: 1px; + height: 50px; + background: #000; + top: 85px; + left: calc(50% - 1px); + transform-origin: bottom; + transform: rotate(-145deg); +} +.leg-right { + width: 1px; + height: 50px; + background: #000; + top: 85px; + left: calc(50%); + transform-origin: bottom; + transform: rotate(145deg); +} + +@keyframes wave { + 0% { + transform-origin: bottom; + transform: rotate(-45deg); + } + 10% { + transform-origin: bottom; + transform: rotate(-75deg); + } + 20% { + transform-origin: bottom; + transform: rotate(-45deg); + } +} */ +/* display hide */ +if wrong guess, display on thru js */ \ No newline at end of file diff --git a/06week/hangman.html b/06week/hangman.html new file mode 100644 index 000000000..435a354de --- /dev/null +++ b/06week/hangman.html @@ -0,0 +1,37 @@ +
+ + + +