From f77202594666d102d3cc70ba0c59081042e084d6 Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Thu, 13 Jul 2017 18:34:39 -0500 Subject: [PATCH 1/3] Class 1 Datatypes --- 01week/javascripting/datatypes.js | 95 +++++++++++++++++++++++++++++ 01week/javascripting/hungerGames.js | 30 +++++++++ 2 files changed, 125 insertions(+) create mode 100644 01week/javascripting/datatypes.js create mode 100644 01week/javascripting/hungerGames.js diff --git a/01week/javascripting/datatypes.js b/01week/javascripting/datatypes.js new file mode 100644 index 000000000..b3b4a4e5a --- /dev/null +++ b/01week/javascripting/datatypes.js @@ -0,0 +1,95 @@ +'use strict'; + +/** +- write a function for current date and time +- wite a function to convert a number to a string +- write a function to convert a string to a number +- write a function that takes in different datatypes and prints out what they are +- write a function that adds 2 numbers together +- write a function that only runs when 2 things are true +- write a function that runs when 1 of 2 things are true +- write a function when both things are NOT true +**/ + +//Current Date & Time +function returnDate() { + let now = new Date(); + return now; +} +console.log( returnDate()); + + +//Convert # to String +function numToString(x) { + return x.toString(); +} +numToString(17); + + +//Convert a String to # +function stringToNum(x) { + let a = parseInt(x); + console.log(a); + return a; +} +stringToNum('5'); + + +//Different datatypes +function typeOf(datatype) { + return typeof datatype; +} + console.log(typeof false); + console.log(typeof null); + console.log(typeof myLife); + console.log(typeof 1.08); + console.log(typeof NaN); + console.log(typeof "I love JS!"); +typeOf(5); + + +//Add 2 #s +function addition(x, y) { + console.log(x + y); + return x + y; +} +addition(5,5); + + +//Two things are true +function theTruth() { + if (9 > 8 && 8 > 7) { + console.log("Numbers never lie!"); + return true; +} else { + console.log("Numbers aren't the source of truth."); + return false; +} +} +theTruth(); + + +//One of two things are true +function theTruth() { + if (9 > 8 && 9 > 10) { + console.log("Nine is the greatest number!"); + return true; +} else { + console.log("Nine is only greater than eight."); + return false; +} +} +theTruth(); + + +//Both not true +function theTruth() { + if (9 === 8 && 8 === 7) { + console.log("Numbers never lie!"); + return true; +} else { + console.log("Numbers aren't the source of truth after all."); + return false; +} +} +theTruth(); diff --git a/01week/javascripting/hungerGames.js b/01week/javascripting/hungerGames.js new file mode 100644 index 000000000..e8be2d8c8 --- /dev/null +++ b/01week/javascripting/hungerGames.js @@ -0,0 +1,30 @@ +'use strict'; + +/** +* pick a random 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 var, pick a random names +* +* return a name +**/ + +const studentArray = ['Ryan', 'Renata', 'Trevor'] + +function randomNumberInRange(top, bottom) { + return Math.floor(Math.random() * (top - bottom + 1)) + bottom; //The maximum is inclusive and the minimum is inclusive +} + +console.log(randomNumberInRange(2,0)); + +function generateRandomName() { + const index = randomNumberInRange(studentArray.length -1, 0); + return studentArray[index]; +} + +console.log(generateRandomName); From bd12be2f700a7fc8550a073dd5a6ae187f32f8c2 Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Sun, 6 Aug 2017 22:02:27 -0500 Subject: [PATCH 2/3] datatypes corrections --- 01week/javascripting/datatypes.js | 102 ++++++++++++++++++------------ 04week/functional-javascript.js | 6 ++ 04week/higherOrder.js | 36 ++++++----- 3 files changed, 89 insertions(+), 55 deletions(-) create mode 100644 04week/functional-javascript.js diff --git a/01week/javascripting/datatypes.js b/01week/javascripting/datatypes.js index b3b4a4e5a..e466dd967 100644 --- a/01week/javascripting/datatypes.js +++ b/01week/javascripting/datatypes.js @@ -12,33 +12,41 @@ **/ //Current Date & Time -function returnDate() { - let now = new Date(); - return now; -} -console.log( returnDate()); + +//function returnDate() { + //return new Date; +//} +//console.log(returnDate()); +const returnDate = () => new Date; +console.log(returnDate()); //Convert # to String -function numToString(x) { - return x.toString(); -} + +// function numToString(x) { +// return x.toString(); +// } +// numToString(17); +const numToString = (x) => x.toString(); numToString(17); //Convert a String to # -function stringToNum(x) { - let a = parseInt(x); - console.log(a); - return a; -} + +// function stringToNum(x) { +// return parseInt(x); +// } +// stringToNum('5'); +const stringToNum = (x) => parseInt(x); stringToNum('5'); //Different datatypes -function typeOf(datatype) { - return typeof datatype; -} + +// function typeOf(datatype) { +// return typeof datatype; +// } +const typeOf = (datatype) => typeof datatype; console.log(typeof false); console.log(typeof null); console.log(typeof myLife); @@ -49,47 +57,63 @@ typeOf(5); //Add 2 #s -function addition(x, y) { - console.log(x + y); - return x + y; -} + +// function addition(x, y) { +// console.log(x + y); +// return x + y; +// } +// addition(5,5); +const addition = (x, y) => (x + y); addition(5,5); //Two things are true -function theTruth() { - if (9 > 8 && 8 > 7) { - console.log("Numbers never lie!"); + +// function theTruth() { +// if (9 > 8 && 8 > 7) { +// console.log("Numbers never lie!"); +// return true; +// } else { +// console.log("Numbers aren't the source of truth."); +// return false; +// } +// } +// theTruth(); +const twoNumbers = (numOne, numTwo) => { + if (numOne%numTwo===0) { return true; -} else { - console.log("Numbers aren't the source of truth."); - return false; + } } -} -theTruth(); +twoNumbers(10, 5); //One of two things are true -function theTruth() { - if (9 > 8 && 9 > 10) { - console.log("Nine is the greatest number!"); +const theTruth = (arg1,arg2) => { + if (9 > 8 || 9 > 10) { return true; } else { - console.log("Nine is only greater than eight."); - return false; + return false; } } theTruth(); //Both not true -function theTruth() { - if (9 === 8 && 8 === 7) { - console.log("Numbers never lie!"); +// function theTruth() { +// if (9 === 8 && 8 === 7) { +// console.log("Numbers never lie!"); +// return true; +// } else { +// console.log("Numbers aren't the source of truth after all."); +// return false; +// } +// } +// theTruth(); +const theTruth = (num1,num2) => { + if (num1 + num2 === 'string') { return true; } else { - console.log("Numbers aren't the source of truth after all."); - return false; + return false; } } -theTruth(); +theTruth(3, 4); diff --git a/04week/functional-javascript.js b/04week/functional-javascript.js new file mode 100644 index 000000000..ea82b8699 --- /dev/null +++ b/04week/functional-javascript.js @@ -0,0 +1,6 @@ +'use strict' + +function upperCaser(input) { + return input.toUpperCase(); + } +console.log(upperCaser("Hello World!")); diff --git a/04week/higherOrder.js b/04week/higherOrder.js index 73926e3dc..1b17cf6f5 100644 --- a/04week/higherOrder.js +++ b/04week/higherOrder.js @@ -1,26 +1,30 @@ 'use strict'; -const assert = require('assert'); +const arr = [1, 2, 6, 10, 12]; -function forEach(arr, callback) { - // Your code here -} +arr.forEach((num) => { + console.log(num + 2); +}); -function map(arr, callback) { - // Your code here -} +const addTwo = arr.map((num) => { + return num + 2; +}); +console.log(addTwo); -function filter(arr, callback) { - // Your code here -} +const numLessFive = arr.filter((num) => { + return num < 5; +}); +console.log(numLessFive); -function some(arr, callback) { - // Your code here -} +const numAboveEleven = arr.some((num) => { + return num > 11; +}); +console.log(numAboveEleven); -function every(arr, callback) { - // Your code here -} +const numAboveSeven = arr.every((num) => { + return num > 7; +}); +console.log(numAboveSeven); if (typeof describe === 'function') { From e4bd9924260db8a85b0526ef93fe43c2cf7af670 Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Sun, 6 Aug 2017 22:06:57 -0500 Subject: [PATCH 3/3] commit2 --- 01week/javascripting/datatypes.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/01week/javascripting/datatypes.js b/01week/javascripting/datatypes.js index e466dd967..0866e5864 100644 --- a/01week/javascripting/datatypes.js +++ b/01week/javascripting/datatypes.js @@ -47,12 +47,12 @@ stringToNum('5'); // return typeof datatype; // } const typeOf = (datatype) => typeof datatype; - console.log(typeof false); - console.log(typeof null); - console.log(typeof myLife); - console.log(typeof 1.08); - console.log(typeof NaN); - console.log(typeof "I love JS!"); +console.log(typeof false); +console.log(typeof null); +console.log(typeof myLife); +console.log(typeof 1.08); +console.log(typeof NaN); +console.log(typeof "I love JS!"); typeOf(5); @@ -91,9 +91,9 @@ twoNumbers(10, 5); const theTruth = (arg1,arg2) => { if (9 > 8 || 9 > 10) { return true; -} else { - return false; -} + } else { + return false; + } } theTruth(); @@ -109,11 +109,11 @@ theTruth(); // } // } // theTruth(); -const theTruth = (num1,num2) => { +const noTruth = (num1,num2) => { if (num1 + num2 === 'string') { return true; -} else { - return false; -} + } else { + return false; + } } -theTruth(3, 4); +noTruth(3, 4);