diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..32d5b0291 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,51 @@ +// 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 diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..41f578742 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -8,9 +8,86 @@ const rl = readline.createInterface({ }); -function rockPaperScissors(hand1, hand2) { +function rockPaperScissors(userOne, userTwo) { - // 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); } 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')); 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) ); 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();