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
47 changes: 47 additions & 0 deletions 02week/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

let cars = ['Ford', 'Mazda', 'Toyota', 'Chevrolet'];
console.log(cars.length);

let moreCars = ['Mitsubishi', 'Tesla', 'Audi', 'Honda'];
let totalCars = cars.concat(moreCars);
console.log(totalCars);

console.log(moreCars.indexOf('Honda'));
console.log(cars.lastIndexOf('Ford'));

let stringOfCars = totalCars.join();
console.log(stringOfCars);

console.log(stringOfCars.split());

let carsInReverse = totalCars.reverse();
console.log(carsInReverse);

console.log(carsInReverse.sort());

let carsRemoved = carsInReverse.slice(2,4);
console.log(carsRemoved);

console.log(carsInReverse.splice(2,2, 'Ford', 'Honda'));

console.log(carsInReverse.push('Ford', 'Honda'));

carsInReverse.pop();
console.log(carsInReverse);

carsInReverse.shift();
console.log(carsInReverse);

carsInReverse.unshift('BMW');
console.log(carsInReverse);

/*let numbers = [23, 45, 0, 2];
function incrementTwo(item) {
console.log(item + 2);
}
numbers.forEach(incrementTwo)*/

for(let i=0; i < carsInReverse.length; i++){
console.log(carsInReverse[i]);
}
41 changes: 41 additions & 0 deletions 02week/pigLatin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,49 @@ function pigLatin(word) {

// Your code here


const translate = (word) => {
let array = word.split('');
let vowels = ['a','e','i','o','u'];
let newWord = '';
for (let i = 0; i < vowels.length-1; i++){
for (let y = 0; y < word.length-1; y++){
if (word[y] === vowels[i]) {
for(let x = y; x < word.length; x++){
newWord = newWord + word[x];
}
for(let n = 0; n < y; n++){
newWord = newWord + word[n];
}
return newWord + 'ay';
}
}
}
}
}
pigLatin('car');

/*var translate = function(word) {
var array = word.split('');
var vowels = ['a','e','i','o','u'];
var newWord = '';
for(var i = 0; i < vowels.length-1; i++) {
for(var y = 0; y < word.length-1; y++) {
if(word[y] === vowels[i]) {
for(var x = y; x < word.length; x++){
newWord = newWord + word[x];
}
for(var n = 0; n < y; n++){
newWord = newWord + word[n];
}
return newWord + "ay";
}
}
}
}

translate("car");*/


function getPrompt() {
rl.question('word ', (answer) => {
Expand Down
35 changes: 35 additions & 0 deletions 03week/Loops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
let cars = ['Ford', 'Mazda', 'Toyota', 'Chevrolet'];
let moreCars = ['Mitsubishi', 'Tesla', 'Audi', 'Honda'];
let totalCars = cars.concat(moreCars);
let carsInReverse = totalCars.reverse();
for(let i=0; i < carsInReverse.length; i++){
console.log(carsInReverse[i]);
}

let persons = {
firstName: "Jane",
lastName: "Doe",
birthDate: "Jan 5, 1925",
gender: "female"
};

for (var prop in persons) {
console.log(`persons.${prop} = ${persons[prop]}`);
}

for(key in persons){
if (key === 'birthDate'){
console.log(persons['birthDate']);
}
}

let number = 0
while (number < 1000){
//console.log(number);
number += 1
}

do {
//console.log(number);
number +=1
}while(number<1000);
28 changes: 28 additions & 0 deletions 03week/partnerChallenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
//create an object and assign it to a variable named "partnerObj"
//inside partnerObj make 5 key/value pairs one of wich must be a method
const partnerObj = {
firstName:"Chase",
lastName:"Turner",
age:24,
hairColor:"Black",
fullName () {
return `Hello, my name is ${this.firstName} ${this.lastName}`;
}
};
//print out the results of the partnerObj method
partnerObj.fullName();
//print out 2 values in partnerObj
console.log(partnerObj.age, partnerObj.hairColor);
//reassign 1 value in partnerObj to 'cars'
partnerObj.age = 'cars'

console.log(partnerObj);
//make an array from all of the object keys store in a variable named partnerArr
const partnerArr = Object.keys(partnerObj);
console.log(partnerArr);
//for every key in the object print out the key and the value
for (const prop in partnerObj) {
console.log(`${prop}
${partnerObj[prop]}`);
}
38 changes: 35 additions & 3 deletions 03week/towersOfHanoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,56 @@ function printStacks() {
console.log("c: " + stacks.c);
}

function movePiece() {
function movePiece(startStack,endStack) {
// Your code here

const startArray = getStackArrays(startStack)
const endArray = getStackArrays(endStack)
const targetPiece = startArray.pop()
endArray.push(targetPiece);
console.log(targetPiece);
console.log(endArray)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semicolon missing here.

}

function isLegal() {
function getStackArrays(targetStack){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a little redundant. For example, on line 24 you could simply run:

startArray = stacks[startStack]

return stacks[targetStack]
}
function isLegal(startStack,endStack) {
// Your code here

// check if end stack is empty
const startArray = getStackArrays(startStack)
const endArray = getStackArrays(endStack)


if (endArray.length === 0){
return true
}else{
const startItem = startArray.pop()
const endItem = endArray.pop()
if (startItem < endItem){
return true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your isLegal fucntion never returns false.

}
}
}

function checkForWin() {
// Your code here


if (endArray === [4,3,2,1]){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check for [4,3,2,1] in b or c stack.

return 'Win';
}
}

function towersOfHanoi(startStack, endStack) {
// Your code here
if (isLegal(startStack,endStack)){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice concise if statement to check for move legality.

movePiece(startStack,endStack);

}
else {
return "Try again.";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code never runs checkForWin()

}
}

function getPrompt() {
Expand Down