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
81 changes: 81 additions & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
`use strict`

//returns current date and time
//create a function that inputs the year, month, and day
//make new var to store the today var and toDateString method
//use var today with toDateString method

function dateDisplay(year, month, date) {
var today = new Date(year, month, date);
return today.toDateString();
}

dateDisplay(1985, 10, 1);

//create a function with one argument.
//the argument should be a number
//return the argument with the toString() method to make the number a string

function toNumber(number) {
return number.toString()
}

toNumber(13);

//create a fucntion that receives one argument
//argument should be a string
//use parseInt() method on argument to pull a number out

function stringNum(str){
return parseInt(str);
}

stringNum('15 years');

//create a function with one argument
//use the typeOf method on the argument and return the result

function dataType(dT){
return typeof(dT);
}

dataType(`words words words`);

//Create a function with two arguments
//Inside the function, add the two var together
//Use parseInt() to take the number out of the string

function add(numOne, numTwo) {
return parseInt(numOne) + parseInt(numTwo)
}

add(`13`, `17`);

//write a function that returns a true if two var are truthy
//if both var are true, show "nope"
//if both var are false, also show "nope"
// if one is false and one is true, show "yep!"

function truest(thingOne, thingTwo) {
if ((thingOne === true && thingTwo === true) || (thingOne === false && thingTwo === false)){
return `nope`;
} else {
return 'yep!';
}
}

truest(true, false);

//write a function with two arguments
//if both arguments are false, show a confirmation message
//if either argument is true, return a negative response

function womp(dumb, dumber) {
if (dumb === false && dumber === false) {
return `yes, they're both false`
} else {
return 'nah, try again'
}
};

womp(false, true);
51 changes: 0 additions & 51 deletions 02week/pigLatin.js

This file was deleted.

67 changes: 67 additions & 0 deletions 02week/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

const assert = require('assert');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});


function rockPaperScissors(hand1, hand2) {
// check for a tie, if it is a tie, return tie, if not check for win
// rock beats scissors, scissors beats paper, paper beats rock
//to find who won, compare hand1 to hand2
const handOne = 'Hand one wins!'
const handTwo = 'Hand two wins!'

if(hand1 === hand2) {
return "It's a tie!";
} else if (hand1 === 'rock'){
return hand2 === 'paper' ? handTwo : handOne;
} else if (hand1 === 'paper') {
return hand2 === 'scissors' ? handTwo : handOne;
} else if (hand1 === 'scissors') {
return hand2 === 'rock' ? handTwo : handOne;
}
};

function getPrompt() {
rl.question('hand1: ', (answer1) => {
rl.question('hand2: ', (answer2) => {
console.log( rockPaperScissors(answer1, answer2) );
getPrompt();
});
});
}

// Tests

if (typeof describe === 'function') {

describe('#rockPaperScissors()', () => {
it('should detect a tie', () => {
assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!");
assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!");
assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!");
});
it('should detect which hand won', () => {
assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!");
assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!");
assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!");
assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!");
assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!");
assert.equal(rockPaperScissors('paper', 'rock'), "Hand one wins!");
});
it('should scrub input to ensure lowercase with "trim"ed whitepace', () => {
assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!");
assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!");
assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!");
});w
// it('should detect ')
});
} else {

getPrompt();

}
14 changes: 13 additions & 1 deletion 04week/functional-javascript/helloWorld.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
'use strict'

//# 1
function upperCaser(input) {
return input.toUpperCase();
}
};

module.exports = upperCaser


//# 3
var numbers = [1, 5, 10, 15];
var doubles = numbers.map(function(x) {
return x * 2;
};

//# 4
9 changes: 9 additions & 0 deletions 04week/gitOlympics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

const names = ['athens', 'berlin', 'atlanta', 'seoul', 'los angeles']

const printListOfOlympics=(arr)=>{
arr.forEach(i => console.log(i))
}

printListOfOlympics(names);
73 changes: 73 additions & 0 deletions 06week/Checkpoint2Objects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
'use strict'

//Take the following array of objects and console.log each user and their corresponding data in the following form: "user_name paid amount for product in city, state." using map.

// let userArray = [
// {
// "customer": {
// "id": 1,
// "customerName":"Marilyn Monroe",
// "customerCity":"New York City",
// "customerState":"NY",
// "product":"Yellow Chair",
// "productPrice": 19.99
// }
// },
// {
// "customer": {
// "id": 2,
// "customerName":"Abraham Lincoln",
// "customerCity":"Boston",
// "customerState":"MA",
// "product":"Movie Tickets",
// "productPrice": 27.00
// }
// },
// {
// "customer": {
// "id": 3,
// "customerName":"John F. Kennedy",
// "customerCity":"Dallas",
// "customerState":"TX",
// "product":"Mustang Convertible",
// "productPrice": 24999.99
// }
// },
// {
// "customer": {
// "id": 4,
// "customerName":"Martin Luther King",
// "customerCity":"Birmingham",
// "customerState":"AL",
// "product":"Sandwiches",
// "productPrice": 7.99
// }
// },
// ];

//Create a new class called customer. it is made out of an id number, a name, city, state, product, and price. Include a statement that prints out the sentence required for the assignment
class Customer {

Choose a reason for hiding this comment

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

This is unnecessary.

constructor(id, customerName, customerCity, customerState, product, productPrice){
this.id = id;
this.customerName = customerName;
this.customerCity = customerCity;
this.customerState = customerState;
this.product = product;
this.productPrice = productPrice;
}
statement(){
return this.customerName + ' paid ' + this.productPrice + ' for ' + this.product + ' in ' + this.customerCity + ', ' + this.customerState + '.';
}
}

//make new instances of Customer. Use the keys and values listed in the assignment
let marilyn = new Customer(1, 'Marilyn Monroe', 'New York City', 'NY', 'Yellow Chair', '19.99');

Choose a reason for hiding this comment

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

All of these should be const.

let abe = new Customer(2, 'Abraham Lincoln', 'Boston', 'MA', 'Tickets', 27.00);
let john = new Customer(3, 'John F. Kennedy', 'Dallas', 'TX', 'Mustang Convertible', 2499.99);

Choose a reason for hiding this comment

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

This method would require someone to physically type out all of the items in the array, what if the array changes ? What if the array had 5,000 users? You need to use a higher order loop like forEach or map that would loop through this array and print out a string in the given format for every user.

let martin = new Customer(4, 'Martin Luther King', 'Birmingham', 'AL', 'Sandwiches', 7.99);

//console log the statements from Customer
console.log(marilyn.statement());
console.log(abe.statement());
console.log(john.statement());
console.log(martin.statement());
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 Eric, how are you!</h1>
</body>
</html>