diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..290e35c20 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,59 @@ +//Write a JavaScript program to display the current day and time. +console.log(Date()); + +//Write a JavaScript program to convert a number to a string. + +const numberToString = (num) => { + return num.toString() +} +console.log(numberToString(2)); + +//Write a JavaScript program to convert a string to the number. + +const stringToNumber = (str) => { + return parseInt(str, 10 ); +} +console.log(stringToNumber('42')); + +/*Write a JavaScript program that takes in different datatypes and prints out whether they are a: +Boolean*/ + +function isVar(bln){ + return typeof bln; +} +console.log(isVar(42)); + + +//Write a JavaScript program that adds 2 numbers together. + +function addNums(num1, num2){ + return num1 + num2; +} +console.log(addNums(5,2)) + +//Write a JavaScript program that runs only when 2 things are true. + +function twoTrue(x,y){ + if(x==1 && y==2){ + return addNums(4,5); +}} + +console.log(twoTrue(1,2)); + +//Write a JavaScript program that runs when 1 of 2 things are true + +function oneTrue(x,y){ + if(x==1 || y==2){ + return addNums(3,3); + } +} +console.log(oneTrue(0,2)); + +//Write a JavaScript program that runs when both things are not true. +function noneTrue(x,y){ + if(!(x==1) && !(y==2)){ + return addNums(4,4); + } +} +console.log(noneTrue(12,1)); + diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..71a6eda1b 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -8,16 +8,39 @@ const rl = readline.createInterface({ }); -function rockPaperScissors(hand1, hand2) { +function rockPaperScissors(a, b){ + var hand1 = a.trim().toLowerCase(); + var hand2 = b.trim().toLowerCase(); // Write code here + if(hand1 === hand2){ + return "It's a tie!"; + } + else if(hand1 === "rock" && hand2 === "scissors"){ + return "Hand one wins!"; + } + else if(hand1 === "paper" && hand2 === "rock"){ + return "Hand one wins!"; + } + else if(hand1 === "scissors" && hand2 === "paper"){ + return "Hand one wins!"; + } + else if(hand1 === "rock" && hand2 === "paper"){ + return "Hand two wins!"; + } + else if(hand1 === "scissors" && hand2 === "rock"){ + return "Hand two wins!"; + } + else if(hand1 === "paper" && hand2 === "scissors"){ + return "Hand two wins!"; + } } function getPrompt() { rl.question('hand1: ', (answer1) => { rl.question('hand2: ', (answer2) => { - console.log( rockPaperScissors(answer1, answer2) ); + console.log( rockPaperScissors(answer1, answer2)); getPrompt(); }); }); @@ -48,4 +71,4 @@ if (typeof describe === 'function') { getPrompt(); -} +} \ No newline at end of file diff --git a/02week/exercises.js b/02week/exercises.js new file mode 100644 index 000000000..4e83c7fcf --- /dev/null +++ b/02week/exercises.js @@ -0,0 +1,104 @@ +'use strict'; +//length +//Create an array called cars which consists of 4 different types of cars. The first car type should be Ford. +//Console.log the length of the array. +let cars = ["ford", "toyota", "bmw", "chevrolet"]; +console.log(cars.length); + +//concat +//Create another array called more cars with 4 more different types of cars. The last car type should be Honda. +//Use the concat method to combine the cars and moreCars arrays into an array called totalCars. + +let moreCars = ["scion", "ferrari", "acura", "honda"]; +let totalCars = cars.concat(moreCars); + +//indexOf and lastIndexOf +//Use the indexOf method to console.log the index of Honda. +//Use the lastIndexOf method to console.log the index of Ford. + + +console.log(totalCars.indexOf("honda")); +console.log(totalCars.lastIndexOf("Ford")); + +//join +//Use the join method to covert the array totalCars into a string called stringOfCars. + + +let stringOfCars = totalCars.join(" "); +console.log(stringOfCars); + +//split +//Use the split method to convert stringOfCars back intro an array called totalCars. + +totalCars = stringOfCars.split(' '); +console.log(totalCars); + +//reverse +//Use the reverse method to create an array carsInReverse which is the array totalCars in reverse. + +let carsInReverse = totalCars.reverse(); +console.log(carsInReverse); + +//sort +//Use the sort method to put the array carsInReverse into alphabetical order. +//Based on the types of cars you used, predict which item in the array should be at index 0. +//Use the following code to confirm or reject your prediction: + +carsInReverse.sort(); +console.log(carsInReverse.indexOf('acura').toString()); + +//slice +//Use the slice method to remove Ford and Honda from the carsInReverse array and move them into a new array called removedCars. + +let removedCars = carsInReverse.slice(4,6); +console.log(removedCars); +console.log(carsInReverse); + +//splice +//Use the splice method to remove the 2nd and 3rd items in the array carsInReverse and add Ford and Honda in their place. +carsInReverse.splice(1,2,"ford","honda"); +console.log(carsInReverse); + + + + +//push +//Use the push method to add the types of cars that you removed using the splice method to the carsInReverse array. + +carsInReverse.push("bmw", "chevrolet"); +console.log(carsInReverse); + + +//pop +//Use the pop method to remove and console.log the last item in the array carsInReverse. +console.log(carsInReverse.pop()); + + +//shift +//Use the shift method to remove and console.log the first item in the array carsInReverse. + + +console.log(carsInReverse.shift()); + +//unshift +//Use the unshift method to add a new type of car to the array carsInReverse. +carsInReverse.unshift("tesla"); + + + + +//forEach + +//Create an array called numbers with the following items: 23, 45, 0, 2 Write code that will add 2 to each item in the array numbers. +//.forEach() requires a function to be passed into it as its first argument. Build a function that will add 2 and then use .forEach() to pass each number into your freshly built function. const numbers = [23, 45, 0 , 2, 8, 44, 100, 1, 3, 91, 34] + +let numbers = [23, 45, 0, 2]; +let arr = []; +function addNum(num){ + num = num + 2; + arr.push(num); +} + +numbers.forEach(addNum); + +console.log(arr); diff --git a/03week/03week:day2discussion b/03week/03week:day2discussion new file mode 100644 index 000000000..08d1e31c4 --- /dev/null +++ b/03week/03week:day2discussion @@ -0,0 +1 @@ +var str = str.split() \ No newline at end of file diff --git a/03week/03week:day2discussion.js b/03week/03week:day2discussion.js new file mode 100644 index 000000000..d08e1033f --- /dev/null +++ b/03week/03week:day2discussion.js @@ -0,0 +1,21 @@ +'use strict'; +const myString = "This is for your own personal journey. May you have excellent navigation as a developer using your own compass." +// function findLongestWord(myString){ + +// var myStringArray = myString.split(" "); +// var longestWord = 0; +// var myword = None; +// for(i = 0; i < myStringArray.length; i++){ +// if(myStringArray[i] > longestWord){ +// longestWord = myStringArray[i].length(); +// myword= myStringArray[i]; +// } + +// } + +// return myword; + +// } + +// console.log(findLongestWord(myString)); +console.log(myString.split(" ")); \ No newline at end of file diff --git a/03week/checkpoint3 b/03week/checkpoint3 new file mode 100644 index 000000000..e69de29bb diff --git a/03week/checkpoint3.js b/03week/checkpoint3.js new file mode 100644 index 000000000..e69de29bb diff --git a/03week/ticTacToe.js b/03week/ticTacToe.js index 1abf5b900..454566a8c 100644 --- a/03week/ticTacToe.js +++ b/03week/ticTacToe.js @@ -13,6 +13,7 @@ let board = [ ]; let playerTurn = 'X'; +checkForWin(); function printBoard() { console.log(' 0 1 2'); @@ -25,22 +26,78 @@ function printBoard() { function horizontalWin() { // Your code here + + if (board[0].every(cell => cell === playerTurn) || board[1].every(cell => cell === playerTurn) || board[2].every(cell => cell === playerTurn)){ + return true; + console.log("you won horizontal"); + } + else if (board[0].every(cell => cell === playerTurn) || board[1].every(cell => cell === playerTurn) || board[2].every(cell => cell === playerTurn)){ + return true; + console.log("you won horizontal"); + } + else{ + return false; + } } + function verticalWin() { // Your code here + + if (board[0][1] === playerTurn && board[1][1] === playerTurn && board[2][1] === playerTurn ){ + return true; + console.log("you won vertical"); + } + else if (board[0][0] === playerTurn && board[1][0] === playerTurn && board[2][0] === playerTurn ){ + return true; + console.log("you won vertical"); + } + else if (board[0][2] === playerTurn && board[1][2] === playerTurn && board[2][2] === playerTurn ){ + return true; + console.log("you won vertical"); + } + else{ + return false; + } + + } function diagonalWin() { // Your code here + if (board[0][0] === playerTurn && board[1][1] === playerTurn && board[2][2] === playerTurn ){ + return true; + console.log("you win diagonal"); + } + else if (board[0][2] === playerTurn && board[1][1] === playerTurn && board[2][0] === playerTurn ){ + return true; + console.log("you win diagonal"); + } + else{ + return false; + } + } function checkForWin() { // Your code here + if (diagonalWin() === true || verticalWin() === true || horizontalWin() === true){ + return true; + } + return false; } function ticTacToe(row, column) { - // Your code here + board[row][column] = playerTurn; + checkForWin(); + + if( playerTurn === 'X'){ + playerTurn = 'O'; + } + else{ + playerTurn = 'X'; + } + } function getPrompt() { diff --git a/05week/spaceTravelToMars.js b/05week/spaceTravelToMars.js index ce258a382..bc951650c 100644 --- a/05week/spaceTravelToMars.js +++ b/05week/spaceTravelToMars.js @@ -10,6 +10,42 @@ let jobTypes = { }; // Your code here +class CrewMember { + constructor(name, job, specialSkill){ + this.name = name; + this.job = job; + this.specialSkill = specialSkill; + this.ship = null; + } + + enterShip(mav){ + this.ship = mav; + mav.crew.push(this); + + + } +} + + +class Ship { + constructor(name, type, ability){ + this.name = name; + this.type = type; + this.ability = ability; + this.crew = []; + } + +missionStatement(a){ + if(this.crew.length == 0 && CrewMember.ship == null) + return `Can't perform a mission yet.` + return this.ability; + +} + + + +} + //tests if (typeof describe === 'function'){ @@ -57,3 +93,5 @@ if (typeof describe === 'function'){ }); }); } + + diff --git a/index.html b/index.html index a8de93e90..1bdfba12c 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,6 @@