From 2647ceef1dc0f0ec4088343a1c1cc13f6209dbb5 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 23 Jan 2018 14:51:59 -0600 Subject: [PATCH 1/6] data types --- 01week/datatypes.js | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/01week/datatypes.js b/01week/datatypes.js index e69de29bb..350f8308b 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -0,0 +1,70 @@ +1. Write a JavaScript program to display the current day and time. +function findTime(){ +const now = new Date(); //find date +const date = (now.getMonth() + 1) + "/" + now.getDate(); //display month/day +const time = now.getHours() + ":" + now.getMinutes(); //display hour:minute +const dayArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; //array for day of the week +const day = dayArray[now.getDay()]; //get string day of week +const dateTime = "It is " + day + ", " + date + " at " + time + "."; //display time and date in string +return dateTime; +} + +findTime(); + +2. Write a JavaScript program to convert a number to a string. + +function numToString(num){ + return num.toString(); +} +numToString(30) + + +3. Write a JavaScript program to convert a string to the number. + +function stringToNum(string){ + return Number(string); +} +stringToNum('89') + + +4. Write a JavaScript program that takes in different datatypes and prints out what type they are. + +function dataType(type){ + return typeof(type); +} +dataType('eklgjheoh') + + +5. Write a JavaScript program that adds 2 numbers together. + +function sumNumbers (num1,num2) { + return num1 + num2 +} +sumNumbers(7, 3000) + +6. Write a JavaScript program that runs only when 2 things are true. + +function bothTrue (arg1, arg2) { + if(arg1 && arg2) { + return 'both are true' +}else{ + return 'nope' +} +} +bothTrue(4, 6); +bothTrue(null, 6); + +7. Write a JavaScript program that runs when 1 of 2 things are true. + +function oneTrueThing(time) { + if (time < 10) { + return "Good morning"; +} else if (time < 20) { + return "Good day"; +} else { + return "Good evening"; +} +// } +// oneTrueThing(21) + +//8. Write a JavaScript program that runs when both things are not true. From 579613d28ddf1d324fde2f3106cd948bbdb2d380 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 25 Jan 2018 20:41:03 -0600 Subject: [PATCH 2/6] rockPaperScissors --- 01week/rockPaperScissors.js | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..4b10ce54c 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -7,10 +7,56 @@ const rl = readline.createInterface({ output: process.stdout }); +// an easier way to do this would have been if (hand1 === hand2) { +//return 'its a tie!'; +//} function rockPaperScissors(hand1, hand2) { + hand1=hand1.toLowerCase(); + hand2=hand2.toLowerCase(); - // Write code here + if (hand1 === 'rock'){ + if (hand2 === 'rock') { + return 'tie'; + } else if (hand2 === 'paper'){ + return 'player 2 wins'; + } else if (hand2 === 'scissors') { + return 'player 1 wins'; + } else { + return 'try again'; + } + }else if (hand1 === 'paper') { + if (hand2 === 'rock') { + return 'player 1 wins'; + } else if (hand2 === 'paper') { + return 'tie'; + } else if (hand2 === 'scissors') { + return 'player 2 wins'; + else { + return 'try again'; + } + } + }else if (hand1 === 'scissors') { + if (hand2 === 'rock') { + return 'player 2 wins'; { + else if (hand2 === 'paper') { + return 'player 1 wins'; { + else if (hand2 === 'scissors') { + return 'tie'; + else { + return 'try again'; + } + } + } + } + } + } + } + // Write code here (above, in this case) + /*step 1 take in hand 1 and take in hand 2. + code block should compare the two arguments hand1 and hand2. + 4-12 will be if/then conditional statements based on each rule. + */ } From 8697f4b8767be0bb5b1514fe4af860e184ad6f58 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 1 Feb 2018 20:43:49 -0600 Subject: [PATCH 3/6] updates --- 01week/datatypes.js | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/01week/datatypes.js b/01week/datatypes.js index 350f8308b..8e4ef7556 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -1,17 +1,16 @@ -1. Write a JavaScript program to display the current day and time. +//1. Write a JavaScript program to display the current day and time. function findTime(){ -const now = new Date(); //find date -const date = (now.getMonth() + 1) + "/" + now.getDate(); //display month/day -const time = now.getHours() + ":" + now.getMinutes(); //display hour:minute -const dayArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; //array for day of the week -const day = dayArray[now.getDay()]; //get string day of week -const dateTime = "It is " + day + ", " + date + " at " + time + "."; //display time and date in string -return dateTime; + const now = new Date(); //find date + const date = (now.getMonth() + 1) + "/" + now.getDate(); //display month/day + const time = now.getHours() + ":" + now.getMinutes(); //display hour:minute + const dayArray = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; //array for day of the week + const day = dayArray[now.getDay()]; //get string day of week + const dateTime = "It is " + day + ", " + date + " at " + time + "."; //display time and date in string + return dateTime; } +findTime() -findTime(); - -2. Write a JavaScript program to convert a number to a string. +//2. Write a JavaScript program to convert a number to a string. function numToString(num){ return num.toString(); @@ -19,7 +18,7 @@ function numToString(num){ numToString(30) -3. Write a JavaScript program to convert a string to the number. +//3. Write a JavaScript program to convert a string to the number. function stringToNum(string){ return Number(string); @@ -27,7 +26,7 @@ function stringToNum(string){ stringToNum('89') -4. Write a JavaScript program that takes in different datatypes and prints out what type they are. +//4. Write a JavaScript program that takes in different datatypes and prints out what type they are. function dataType(type){ return typeof(type); @@ -35,14 +34,14 @@ function dataType(type){ dataType('eklgjheoh') -5. Write a JavaScript program that adds 2 numbers together. +//5. Write a JavaScript program that adds 2 numbers together. function sumNumbers (num1,num2) { return num1 + num2 } sumNumbers(7, 3000) -6. Write a JavaScript program that runs only when 2 things are true. +//6. Write a JavaScript program that runs only when 2 things are true. function bothTrue (arg1, arg2) { if(arg1 && arg2) { @@ -54,17 +53,26 @@ function bothTrue (arg1, arg2) { bothTrue(4, 6); bothTrue(null, 6); -7. Write a JavaScript program that runs when 1 of 2 things are true. +//7. Write a JavaScript program that runs when 1 of 2 things are true. -function oneTrueThing(time) { - if (time < 10) { - return "Good morning"; -} else if (time < 20) { - return "Good day"; +function oneTrueThing(arg1, arg2) { + if (arg1 || arg2) { + return "one argument is true"; } else { - return "Good evening"; + return "Neither is true"; +} } -// } -// oneTrueThing(21) +oneTrueThing(true, false) +oneTrueThing(false, true) //8. Write a JavaScript program that runs when both things are not true. + +function bothFalse(arg1, arg2) { + if (!arg1 && !arg2) { + return "both are false" + } else { + return "at least one argument is true" + } +} +bothFalse(null, null) +bothFalse(0, 5) From d221020cbac38e4ee0d86e19a05f7eb1e6bee0b7 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 1 Feb 2018 20:49:13 -0600 Subject: [PATCH 4/6] logic --- 01week/rockPaperScissors.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 4b10ce54c..395df6ecd 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -12,8 +12,16 @@ const rl = readline.createInterface({ //} function rockPaperScissors(hand1, hand2) { +<<<<<<< Updated upstream hand1=hand1.toLowerCase(); hand2=hand2.toLowerCase(); +======= +<<<<<<< Updated upstream +======= + hand1=hand1.toLowerCase().trim(); + hand2=hand2.toLowerCase().trim(); +>>>>>>> Stashed changes +>>>>>>> Stashed changes if (hand1 === 'rock'){ if (hand2 === 'rock') { From 85f643a19bf756c183f3b8a2238f6ae5056eae54 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 8 Feb 2018 13:03:33 -0600 Subject: [PATCH 5/6] minor change --- 01week/rockPaperScissors.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 395df6ecd..222ae7608 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -12,16 +12,9 @@ const rl = readline.createInterface({ //} function rockPaperScissors(hand1, hand2) { -<<<<<<< Updated upstream - hand1=hand1.toLowerCase(); - hand2=hand2.toLowerCase(); -======= -<<<<<<< Updated upstream -======= + hand1=hand1.toLowerCase().trim(); hand2=hand2.toLowerCase().trim(); ->>>>>>> Stashed changes ->>>>>>> Stashed changes if (hand1 === 'rock'){ if (hand2 === 'rock') { From b78fb25a94f6e9102d7953bad5d6a2046b15af2f Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 8 Feb 2018 18:03:58 -0600 Subject: [PATCH 6/6] rock paper scissors corrections --- 01week/rockPaperScissors.js | 56 +++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 222ae7608..07c966625 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -18,49 +18,39 @@ function rockPaperScissors(hand1, hand2) { if (hand1 === 'rock'){ if (hand2 === 'rock') { - return 'tie'; - } else if (hand2 === 'paper'){ - return 'player 2 wins'; - } else if (hand2 === 'scissors') { - return 'player 1 wins'; - } else { - return 'try again'; + return "It's a tie!"; + }else if (hand2 === 'paper'){ + return "Hand two wins!"; + }else if (hand2 === 'scissors') { + return "Hand one wins!"; + }else { + return "try again"; } }else if (hand1 === 'paper') { if (hand2 === 'rock') { - return 'player 1 wins'; - } else if (hand2 === 'paper') { - return 'tie'; - } else if (hand2 === 'scissors') { - return 'player 2 wins'; - else { - return 'try again'; - } + return "Hand one wins!"; + }else if (hand2 === 'paper') { + return "It's a tie!"; + }else if (hand2 === 'scissors') { + return "Hand two wins!"; + }else { + return "try again"; } + }else if (hand1 === 'scissors') { if (hand2 === 'rock') { - return 'player 2 wins'; { - else if (hand2 === 'paper') { - return 'player 1 wins'; { - else if (hand2 === 'scissors') { - return 'tie'; - else { - return 'try again'; - } - } - } - } - } + return "Hand two wins!"; + }else if (hand2 === 'paper'){ + return "Hand one wins!"; + } else if(hand2 === 'scissors') { + return "It's a tie!"; + }else { + return "try again"; } } - // Write code here (above, in this case) - /*step 1 take in hand 1 and take in hand 2. - code block should compare the two arguments hand1 and hand2. - 4-12 will be if/then conditional statements based on each rule. - */ - } + function getPrompt() { rl.question('hand1: ', (answer1) => { rl.question('hand2: ', (answer2) => {