From 44e675a385647329cd4d47755cb2537f776fbb46 Mon Sep 17 00:00:00 2001 From: jmwhitman7 Date: Thu, 13 Jul 2017 18:58:53 -0500 Subject: [PATCH 1/2] datatypes day 1 --- 01week/javascripting/hungergames.js | 27 ++++++++++ 01week/javascripting/introduction.js | 79 +++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 01week/javascripting/hungergames.js diff --git a/01week/javascripting/hungergames.js b/01week/javascripting/hungergames.js new file mode 100644 index 000000000..0b7c70383 --- /dev/null +++ b/01week/javascripting/hungergames.js @@ -0,0 +1,27 @@ +'use strict'; + +/** +* pick a ronadom student from this class +* +* store names in a variable- array +* +* generate a random number, less than amount in class +* +* apply the index to the array +* +* from that array, pick a random one +* +* return a name +* */ + +const studentArray = []; + +function randomNumberInRange (top, bottom){ + return Math.floor( Math.random() * ( 1 + top - bottom ) ) + bottom; +} + +console.log(randomNumberInRange(14, 0)); +function generateRandomName() { + const index = randomNumberInRange(studentArray.length -1, 0); + return studentArray[index]; +} diff --git a/01week/javascripting/introduction.js b/01week/javascripting/introduction.js index e921523b1..95dd4be48 100644 --- a/01week/javascripting/introduction.js +++ b/01week/javascripting/introduction.js @@ -1 +1,78 @@ -console.log('hello'); +'use strict'; + +// Write a JavaScript program to display the current day and time. + +function currentDateTime(){ + console.log(new Date()); +} +currentDateTime(); + + +// Write a JavaScript program to convert a number to a string. + +function numberToString(num){ + console.log(num.toString()); +} +numberToString(10); + + + +// Write a JavaScript program to convert a string to the number. + +function stringToNumber(number){ + console.log(parseInt(number)); +} +stringToNumber(224); + + +// Write a JavaScript program that takes in different datatypes and prints out whether they are a: +// Boolean +// Null +// Undefined +// Number +// NaN +// String + +function ReturnType(someData){ + console.log(typeof someData); +} +ReturnType('Hello'); +ReturnType(10); +ReturnType(); +ReturnType(true); +ReturnType(); + + +// Write a JavaScript program that adds 2 numbers together. + +function addingStuff(dig1, dig2){ + console.log( dig1 + dig2 ); +} +addingStuff(4, 7); + +// Write a JavaScript program that runs only when 2 things are true. +function trueTings (x, y){ + if(x === true && y === true) { + console.log("It's True!"); + } +} +trueTings(true,true); + + +// Write a JavaScript program that runs when 1 of 2 things are true. + +function oneTingTrue (z, p) { + if (p || z === true) { + console.log("There can only be one"); + } +} +oneTingTrue(true, true); + +// Write a JavaScript program that runs when both things are not true. + +function noTrueTings (w, r) { + if (w != 2 && r != 13){ + console.log("Yeah right! Neither are true"); + } +} +noTrueTings(true, true); From eb446d2d1c9877c83673520369746a0fea6c0ca3 Mon Sep 17 00:00:00 2001 From: jmwhitman7 Date: Thu, 13 Jul 2017 19:58:31 -0500 Subject: [PATCH 2/2] datatypes change --- 01week/javascripting/introduction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01week/javascripting/introduction.js b/01week/javascripting/introduction.js index 95dd4be48..3f3452414 100644 --- a/01week/javascripting/introduction.js +++ b/01week/javascripting/introduction.js @@ -40,7 +40,7 @@ ReturnType('Hello'); ReturnType(10); ReturnType(); ReturnType(true); -ReturnType(); +ReturnType(0/0); // Write a JavaScript program that adds 2 numbers together.