Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
@@ -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));

29 changes: 26 additions & 3 deletions 01week/rockPaperScissors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -48,4 +71,4 @@ if (typeof describe === 'function') {

getPrompt();

}
}
104 changes: 104 additions & 0 deletions 02week/exercises.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions 03week/03week:day2discussion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var str = str.split()
21 changes: 21 additions & 0 deletions 03week/03week:day2discussion.js
Original file line number Diff line number Diff line change
@@ -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(" "));
Empty file added 03week/checkpoint3
Empty file.
Empty file added 03week/checkpoint3.js
Empty file.
59 changes: 58 additions & 1 deletion 03week/ticTacToe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let board = [
];

let playerTurn = 'X';
checkForWin();

function printBoard() {
console.log(' 0 1 2');
Expand All @@ -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() {
Expand Down
38 changes: 38 additions & 0 deletions 05week/spaceTravelToMars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down Expand Up @@ -57,3 +93,5 @@ if (typeof describe === 'function'){
});
});
}


2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<title></title>
</head>
<body>
<h1>Hello World!</h1>
<h1>Hello Josh!</h1>
</body>
</html>
Loading