From 2647ceef1dc0f0ec4088343a1c1cc13f6209dbb5 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 23 Jan 2018 14:51:59 -0600 Subject: [PATCH 1/2] 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 ee4cbbf58cf92b463f4528ef01b6c9760f887110 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Thu, 8 Feb 2018 13:17:26 -0600 Subject: [PATCH 2/2] datatypes corrections --- 01week/datatypes.js | 59 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/01week/datatypes.js b/01week/datatypes.js index 350f8308b..372c4ea63 100644 --- a/01week/datatypes.js +++ b/01week/datatypes.js @@ -1,17 +1,17 @@ -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 + 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. +//2. Write a JavaScript program to convert a number to a string. function numToString(num){ return num.toString(); @@ -19,7 +19,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 +27,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,36 +35,45 @@ 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) { - return 'both are true' -}else{ + return 'both are true' + }else{ return 'nope' -} + } } bothTrue(4, 6); bothTrue(null, 6); +bothTrue(3, false) -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"; -} else { - return "Good evening"; +function oneTrueThing(arg1, arg2) { + if (arg1 || arg2) { + return "st least one of these is true"; + } else { + return "neither of these is true"; + } } -// } -// oneTrueThing(21) +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 of these are false" + } else { + return "at least one of the arguments is true" + } +} +bothFalse(4, 0) +bothFalse(0, 0)