From 2b07b9609db44b5b10a7927d070249da868f28ee Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Thu, 10 Jan 2019 17:33:08 -0600 Subject: [PATCH 1/8] WEKK 01 CLASS 01 --- 01week/datatypes.js | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..beccc5878 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,50 @@ +// 1.Write a JavaScript program to display the current day and time. +let date = new Date(); +console.log(date); +"/n" +// 2. Write a JavaScript program to convert a number to a string. +let number2 = 15; +number2 = "This is now a string" +console.log(number2); + +//3. Write a JavaScript program to convert a string to the number. +let string3 = 'String'; +string3= 4; +console.log(string3); + +//4. Write a JavaScript program that takes in different datatypes and prints out whether they are a: +//Boolean +console.log(typeof true); +//Null +console.log(typeof null); +//Undefined +console.log(typeof x); +//Number +console.log(typeof 4); +//NaN +console.log(typeof NaN); +//String +console.log(typeof 'Hello World!'); + +//5.Write a JavaScript program that adds 2 numbers together. +let sum = (2+2); +console.log(sum); + +//6.Write a JavaScript program that runs only when 2 things are true + +let firstStatement = true; +let secondStatement = true; +if (firstStatement && secondStatement){ + console.log('Both are true'); +} + +//7.Write a JavaScript program that runs when 1 of 2 things are true. + +if (firstStatement || secondStatement){ + console.log("At least one is true"); +} + +//8.Write a JavaScript program that runs when both things are not true +if (!firstStatement && !secondStatement ){ + console.log('Both are false') +} \ No newline at end of file From 0afa6ee88a5ac1981d050629561a98e7974153b7 Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Tue, 15 Jan 2019 18:34:43 -0600 Subject: [PATCH 2/8] rock paper scissors 1st submission --- 01week/rockPaperScissors.js | 79 ++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..7b0b7b177 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -10,7 +10,84 @@ const rl = readline.createInterface({ function rockPaperScissors(hand1, hand2) { - // Write code here + + //User1 input of rock, paper, or scissors. +let userOne = "paper" +function userOneChoice(userOne) { + userOne.toLocaleLowerCase(); + if (userOne === 'rock' || userOne === 'paper' || userOne === 'scissors'){ + console.log('User 1 threw ' + userOne) + } else { + console.log('This is not an acceptable value!') + } +}; +userOneChoice(userOne); + + +//User2 input of rock, paper, or scissors. +let userTwo = "rock" +function userTwoChoice(userTwo) { + userOne.toLocaleLowerCase(); + if (userTwo === 'rock' || userTwo === 'paper' || userTwo === 'scissors'){ + console.log('User 2 threw ' + userTwo) + } else { + console.log('This is not an acceptable value!') + } +}; +userTwoChoice(userTwo); + + +//Compare User1 input to User2 input. +function determineWinner (userOne,userTwo){ + + + //If User1 input is 'rock' and User2 input is 'scissor', User1 wins. + if(userOne === 'rock' && userTwo === 'scissors'){ + console.log('User1 wins.') + }; + + //If User1 input is 'rock' and User2 input is 'paper', User2 wins. + if (userOne === 'rock' && userTwo === 'paper'){ + console.log('User2 wins.') + }; + + //If User1 input is 'rock' and User2 input is 'rock', it's a tie. + if (userOne === 'rock' && userTwo === 'rock'){ + console.log("it's a tie") + }; + + //If User1 input is 'paper' and User2 input is 'rock', User1 wins. + if (userOne === 'paper' && userTwo === 'rock'){ + console.log('User1 wins.') + }; + + //If User1 input is 'paper' and User2 input is 'scissors', User2 wins. + if (userOne === 'paper' && userTwo === 'scissors'){ + console.log('User2 wins.') + }; + + //If User1 input is 'paper' and User2 input is 'paper', it's a tie. + if (userOne === 'paper' && userTwo === 'paper'){ + console.log("It's a tie.") + }; + + //If User1 input is 'scissors' and User2 input is 'paper', User1 wins. + if (userOne === 'scissors' && userTwo === 'paper'){ + console.log('User1 wins.') + }; + + //If User1 input is 'scissors' and User2 input is 'rock', User2 wins. + if (userOne === 'scissors' && userTwo === 'rock'){ + console.log('User 2 wins') + }; + + //If User1 input is 'scissors' and User2 input is 'scissors', it's a tie. + if (userOne === 'scissors' && userTwo === 'scissors'){ + console.log("It's a tie.") + }; +}; + +determineWinner(userOne,userTwo); } From 7bd9432823b7c8d3ca9ce25f2eb5260643054cae Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Tue, 15 Jan 2019 18:36:29 -0600 Subject: [PATCH 3/8] datatypes --- 01week/datatypes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/01week/datatypes.js b/01week/datatypes.js index beccc5878..32d5b0291 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -30,6 +30,7 @@ console.log(typeof 'Hello World!'); let sum = (2+2); console.log(sum); + //6.Write a JavaScript program that runs only when 2 things are true let firstStatement = true; From 64da1cc15b3b4ed1127a6d2d0b9ba8ae07e921a2 Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Thu, 17 Jan 2019 17:55:14 -0600 Subject: [PATCH 4/8] pigLatin 1st submission --- 02week/pigLatin.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 046434c94..bcfeda321 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -9,12 +9,18 @@ const rl = readline.createInterface({ function pigLatin(word) { - - // Your code here - + for (i =0; i < word.length; i++) { + let y = ""; + if ( word.charAt(0)=="a" || word.charAt(0)=="e" || word.charAt(0)=="i" || word.charAt(0)=="o" || word.charAt(0)=="u"){ + y = word + "ay"; + return y; + } else if (word.charAt(i)=="a" || word.charAt(i)=="e" || word.charAt(i)=="i" || word.charAt(i)=="o" || word.charAt(i)=="u"){ + y=word.slice(i)+word.slice(0,i) + "ay"; + return y; + } + } } - function getPrompt() { rl.question('word ', (answer) => { console.log( pigLatin(answer) ); From 83c9521b169cced297c5a00ee612ab32a5b9ca73 Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Thu, 17 Jan 2019 17:59:19 -0600 Subject: [PATCH 5/8] rock paper scissors branch --- 01week/rockPaperScissors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 7b0b7b177..8017c12dd 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -20,7 +20,7 @@ function userOneChoice(userOne) { } else { console.log('This is not an acceptable value!') } -}; +}; userOneChoice(userOne); From 9f2f03bd166a20150cfefce7b7a31807aae35cef Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Tue, 22 Jan 2019 13:09:36 -0600 Subject: [PATCH 6/8] 1st changes made to rock paper scissors --- 01week/rockPaperScissors.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 8017c12dd..41f578742 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -8,7 +8,7 @@ const rl = readline.createInterface({ }); -function rockPaperScissors(hand1, hand2) { +function rockPaperScissors(userOne, userTwo) { //User1 input of rock, paper, or scissors. @@ -43,27 +43,27 @@ function determineWinner (userOne,userTwo){ //If User1 input is 'rock' and User2 input is 'scissor', User1 wins. if(userOne === 'rock' && userTwo === 'scissors'){ - console.log('User1 wins.') + console.log('User1 wins!') }; //If User1 input is 'rock' and User2 input is 'paper', User2 wins. if (userOne === 'rock' && userTwo === 'paper'){ - console.log('User2 wins.') + console.log('User2 wins!') }; //If User1 input is 'rock' and User2 input is 'rock', it's a tie. if (userOne === 'rock' && userTwo === 'rock'){ - console.log("it's a tie") + console.log("It's a tie.") }; //If User1 input is 'paper' and User2 input is 'rock', User1 wins. if (userOne === 'paper' && userTwo === 'rock'){ - console.log('User1 wins.') + console.log('User1 wins!') }; //If User1 input is 'paper' and User2 input is 'scissors', User2 wins. if (userOne === 'paper' && userTwo === 'scissors'){ - console.log('User2 wins.') + console.log('User2 wins!') }; //If User1 input is 'paper' and User2 input is 'paper', it's a tie. @@ -73,12 +73,12 @@ function determineWinner (userOne,userTwo){ //If User1 input is 'scissors' and User2 input is 'paper', User1 wins. if (userOne === 'scissors' && userTwo === 'paper'){ - console.log('User1 wins.') + console.log('User1 wins!') }; //If User1 input is 'scissors' and User2 input is 'rock', User2 wins. if (userOne === 'scissors' && userTwo === 'rock'){ - console.log('User 2 wins') + console.log('User 2 wins!') }; //If User1 input is 'scissors' and User2 input is 'scissors', it's a tie. From 371b60bd500537506c39345d8f7621ab1aa8ba22 Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Tue, 22 Jan 2019 13:44:20 -0600 Subject: [PATCH 7/8] array excersies 1st submission --- 02week/exercises.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 02week/exercises.js diff --git a/02week/exercises.js b/02week/exercises.js new file mode 100644 index 000000000..eba4bd6b8 --- /dev/null +++ b/02week/exercises.js @@ -0,0 +1,28 @@ +// 1. create an arrary called cars; console log the length of cars +let cars = ['Ford','Dodge','GMC','Chevrolet'] +// console log the length of cars +console.log(cars.length); + +// 2. crate an array called moreCarsl use concat, create new variable and combine cars and moreCars +let moreCars = ['Audi','BMW','Toyota','Honda']; +// create new variable and combine cars and moreCars +let totalCars = cars.concat(moreCars); + +//3. Use the indexOf method to conole.log the index of Honda; +console.log(moreCars.indexOf('Honda')); +//use the lastIndexOf methon to console.log the index of Ford +console.log(cars.lastIndexOf('Ford')); + +//4. use join to covert totalCars to a string +let stringOfCars = totalCars.join(); + +//5. use split to convert stringOfCars into array called totalCars +totalCars = stringOfCars.split(); + +//6. use the reverse method to creare array which is totalCars in reverse +let carsInReverse = totalCars.reverse(); + +//7. use sort to put in alphabetical order +carsInReverse.sort(); +//predcict which iteam in the array should be at index 0 +alert(carsInReverse.indexOf('Audi')); From f1daabddcfdef7c55b26eb3a663d92296c0cadcd Mon Sep 17 00:00:00 2001 From: Andrew Sommere Date: Thu, 24 Jan 2019 15:19:00 -0600 Subject: [PATCH 8/8] ticTacToe 1st submission --- 03week/ticTacToe.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..bc8396b81 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -24,23 +24,42 @@ function printBoard() { } function horizontalWin() { - // Your code here + // checcks all horizontal possibilites; + if ((board[0][0] == playerTurn && board[0][1] == playerTurn && board[0][2] == playerTurn)||(board[0][1] == playerTurn && board[1][1] == playerTurn && board[2][1] == playTurn) || (board[0][2] == playerTurn && board[1][2] == playerTurn && board[2][2] == playerTurn)){ + return true; + } else { + return false + }; } - function verticalWin() { - // Your code here + // checcks all vertical possibilites; + if ((board[0][0] == playerTurn && board[1][0] == playerTurn && board[2][0] == playerTurn)||(board[1][0] == playerTurn && board[1][1] == playerTurn && board[1][2] == playTurn) || (board[2][0] == playerTurn && board[2][1] == playerTurn && board[2][2] == playerTurn)){ + return true; + } else { + return false + }; } function diagonalWin() { - // Your code here + // checcks all diagonal possibilites; + if ((board[0][0] == playerTurn && board[1][1] == playerTurn && board[2][2] == playerTurn)||(board[0][2] == playerTurn && board[1][1] == playerTurn && board[0][2] == playTurn)){ + return true; + } else { + return false + }; } function checkForWin() { - // Your code here + // checks to see if vertical,diagnol, horizointal win is true; if any are true checkForWin returns true + if (diagonalWin()||verticalWin()||horizontalWin()){ + return true; + } else { + return false; + } } function ticTacToe(row, column) { - // Your code here + // not sure what to do here will ask in class; } function getPrompt() { @@ -52,7 +71,6 @@ function getPrompt() { getPrompt(); }); }); - } @@ -91,3 +109,4 @@ if (typeof describe === 'function') { getPrompt(); } +printBoard();