From f77202594666d102d3cc70ba0c59081042e084d6 Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Thu, 13 Jul 2017 18:34:39 -0500 Subject: [PATCH 1/5] 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 97d35ad654c2f6a8c50e2ea3652a89c84e3d93a0 Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Mon, 17 Jul 2017 23:03:58 -0500 Subject: [PATCH 2/5] RockPaperScissors --- 01week/rockPaperScissors.js | 40 +++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/01week/rockPaperScissors.js b/01week/rockPaperScissors.js index 16f58790a..88723d9ae 100644 --- a/01week/rockPaperScissors.js +++ b/01week/rockPaperScissors.js @@ -1,5 +1,22 @@ 'use strict'; +/**WHITEBOARDING +If/Else Statements +Player 1 & 2 start game by shaking fist 3 times and revealing selection on the 4th. +If Player 1 rock vs rock = ties +-- Player 1 rock vs paper = loses +-- Player 1 rock vs scissors = wins +-- Player 1 paper vs paper = ties +-- Player 1 paper vs scissors = loses +-- Player 1 paper vs rock = wins +etc etc. List out all combos of results. +...SO... +Test if Player 1 Wins, Test if Player 2 Wins, Test if it's a tie. +If (rock) && (rock > scissors).... +Try Switch statement since you have many options to run through. +How can you test hand 1 and hand 2 simultaneously? As if in real life? +**/ + const assert = require('assert'); const readline = require('readline'); const rl = readline.createInterface({ @@ -8,11 +25,26 @@ const rl = readline.createInterface({ }); -function rockPaperScissors(hand1, hand2) { - - // Write code here - +// MY CODE // +function rockPaperScissors(hand1, hand2){ + if (hand1 === 'rock' && hand2 === 'rock') { + console.log("It's a tie!"); + } else if (hand1 === 'paper' && hand2 === 'paper') { + console.log("It's a tie!"); + } else if (hand1 === 'scissors' && hand2 === 'scissors') { + console.log("It's a tie!"); + } else if (hand1 === 'rock' && hand2 === 'rock') { + console.log("It's a tie!"); + } else if (hand1 === 'rock' && hand2 === 'scissors') { + console.log("Player 1 wins!"); + } else if (hand1 === 'rock' && hand2 === 'paper') { + console.log("Player 2 wins!"); + } else if (hand1 === 'paper' && hand2 === 'scissors'){ + console.log("Player 2 wins!"); + } } +console.log(rockPaperScissors('rock', 'scissors')); + function getPrompt() { rl.question('hand1: ', (answer1) => { From 8cb123881dcc001949134b76adfedb5b1ac3d6f9 Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Thu, 20 Jul 2017 18:50:57 -0500 Subject: [PATCH 3/5] pigLatin --- 02week/pigLatin.js | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 046434c94..e088f678a 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -1,5 +1,40 @@ 'use strict'; +/*WHITEBOARDING +-Check beginning of word for vowels. +--If word starts with vowel add 'ay' to end of word +--If consonant, split letters +-Append consonants to the end of word +-THEN add 'ay' to the end +*/ + +//MY CODE +var word = "renata"; +var firstLetter = word.charAt(0); + +function testForVowel(obj) { + var arrayVowels = ['a','e','i','o','u']; + return (arrayVowels.indexOf(obj) != -1); +} +testForVowel(firstLetter) + +function split_letters(letters){ + return (letters.substring(1) + letters.charAt(0)); +} +split_letters(word); + +function addAy(param) { + return param + "ay"; +} +addAy(word); + + + + + + + + const assert = require('assert'); const readline = require('readline'); const rl = readline.createInterface({ @@ -8,10 +43,11 @@ const rl = readline.createInterface({ }); -function pigLatin(word) { - - // Your code here +const translatePigLatin = (word) => { + if (first == "a" || first == "e" || first == "i" || first == "o" || first == "u") +} else { + run again; } From 8130cd29f02d364da0002e5b37589c562252bd0e Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Sun, 30 Jul 2017 20:50:06 -0500 Subject: [PATCH 4/5] pigLatin --- 02week/pigLatin.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index e088f678a..6e86820c4 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -14,7 +14,7 @@ var firstLetter = word.charAt(0); function testForVowel(obj) { var arrayVowels = ['a','e','i','o','u']; - return (arrayVowels.indexOf(obj) != -1); + return (arrayVowels.indexOf(obj) != -1); } testForVowel(firstLetter) @@ -24,17 +24,10 @@ function split_letters(letters){ split_letters(word); function addAy(param) { - return param + "ay"; + return param + "ay"; } addAy(word); - - - - - - - const assert = require('assert'); const readline = require('readline'); const rl = readline.createInterface({ @@ -45,14 +38,12 @@ const rl = readline.createInterface({ const translatePigLatin = (word) => { if (first == "a" || first == "e" || first == "i" || first == "o" || first == "u") - -} else { - run again; -} - + { + return word + "ay"; + }; function getPrompt() { - rl.question('word ', (answer) => { + rl.question('word ', (answer) => { console.log( pigLatin(answer) ); getPrompt(); }); @@ -81,7 +72,5 @@ if (typeof describe === 'function') { }); }); } else { - getPrompt(); - -} +}; From 1f5f0fb54e91c907b9528c336eb2234ee501afac Mon Sep 17 00:00:00 2001 From: Renata Estes Date: Mon, 7 Aug 2017 21:07:43 -0500 Subject: [PATCH 5/5] corrections --- 02week/pigLatin.js | 74 ++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/02week/pigLatin.js b/02week/pigLatin.js index 6e86820c4..fe96ab930 100644 --- a/02week/pigLatin.js +++ b/02week/pigLatin.js @@ -5,28 +5,7 @@ --If word starts with vowel add 'ay' to end of word --If consonant, split letters -Append consonants to the end of word --THEN add 'ay' to the end -*/ - -//MY CODE -var word = "renata"; -var firstLetter = word.charAt(0); - -function testForVowel(obj) { - var arrayVowels = ['a','e','i','o','u']; - return (arrayVowels.indexOf(obj) != -1); -} -testForVowel(firstLetter) - -function split_letters(letters){ - return (letters.substring(1) + letters.charAt(0)); -} -split_letters(word); - -function addAy(param) { - return param + "ay"; -} -addAy(word); +-THEN add 'ay' to the end*/ const assert = require('assert'); const readline = require('readline'); @@ -35,20 +14,59 @@ const rl = readline.createInterface({ output: process.stdout }); +//CORRECTIONS +// function split_letters(letters){ +// return (letters.substring(1) + letters.charAt(0) + "ay"); +// }; +const split_letters = (word) => (word.substring(1)) + word.charAt(0); const translatePigLatin = (word) => { - if (first == "a" || first == "e" || first == "i" || first == "o" || first == "u") - { - return word + "ay"; - }; + let temp = word; + for (let i = 0; i < temp.length; i++) { + const first = temp.charAt(0); + // console.log(first); + if (first == "a" || first == "e" || first == "i" || first == "o" || first == "u") { + return temp + "ay"; + } else { + temp = split_letters(temp); + } + } +}; + function getPrompt() { - rl.question('word ', (answer) => { - console.log( pigLatin(answer) ); + rl.question('word ', (answer) => { + console.log( translatePigLatin(answer) ); getPrompt(); }); } +// const translatePigLatin = (word) => { +// if (first == "a" || first == "e" || first == "i" || first == "o" || first == "u") +// { +// return word + "yay"; +// } else { +// return split_letters(word); +// }; +// translatePigLatin('word'); + +// function testForVowel(obj) { +// var arrayVowels = ['a','e','i','o','u']; +// return (arrayVowels.indexOf(obj) != -1); +// } +// testForVowel(firstLetter) + +// function split_letters(letters){ +// return (letters.substring(1) + letters.charAt(0)); +// } +// split_letters(word); +// +// function addAy(param) { +// return param + "ay"; +// } +// addAy(word); + + // Tests if (typeof describe === 'function') {