diff --git a/01-Fundamentals-Part-1/starter/assignments.js b/01-Fundamentals-Part-1/starter/assignments.js index 4a2a979078..841dbb568e 100644 --- a/01-Fundamentals-Part-1/starter/assignments.js +++ b/01-Fundamentals-Part-1/starter/assignments.js @@ -1,8 +1,6 @@ // JavaScript Fundamentals 1 - -// Values and Variables - +// // Values and Variables // let country = "United States of America"; // let continent = "North America"; // let population = 340.1; @@ -12,8 +10,8 @@ // console.log(population); -// Data Types +// // Data Types // let isIsland = false; // let language; @@ -23,29 +21,115 @@ // console.log(typeof language); -// let, const, and var -const country = "United States of America"; -const continent = "North America"; -let population = 340.1; -const isIsland = false; -const language = "English"; +// // let, const, and var +// const country = "United States of America"; +// const continent = "North America"; +// let population = 340.1; +// const isIsland = false; +// const language = "English"; // isIsland = true; -// Basic Operators -const halfPopulation = population / 2; -console.log(halfPopulation); +// // Basic Operators +// const halfPopulation = population / 2; +// console.log(halfPopulation); + +// population += 1; +// console.log(population); + +// const populationFinland = 6; +// console.log(population > populationFinland); + +// const averagePopulation = 33; +// console.log(population < averagePopulation); + +// const description = country + " is in " + continent + ", and its " + population + " million people speak " + language +// console.log(description); + + + +// // Strings and Template Literals +// const newDescription = `${country} is in ${continent}, and its ${population} million people speak ${language}` +// console.log(newDescription); + -population += 1; -console.log(population); -const populationFinland = 6; -console.log(population > populationFinland); +// // Taking Decisions: if/else Statements +// if (population > averagePopulation) { +// console.log(`${country}'s population is ${population - averagePopulation} above average.`); +// } else { +// console.log(`${country}'s population is ${averagePopulation - population} below average.`); +// } -const averagePopulation = 33; -console.log(population < averagePopulation); -const description = country + " is in " + continent + ", and its " + population + " million people speak " + language -console.log(description); + +// // Type Conversion and Coercion +// console.log("9" - "5"); // 4 +// console.log("19" - "13" + "17"); // "617" +// console.log("19" - "13" + 17); // 23 +// console.log("123" < 57); // false +// console.log(5 + 6 + "4" + 9 - 4 - 2); // 1143 + + + +// // Equality Operators: == vs === +// const numNeighbors = Number(prompt("How many neighboring countries does your country have?")); + +// if (numNeighbors === 1) { +// console.log("Only 1 border!"); +// } else if (numNeighbors > 1) { +// console.log("More than 1 border"); +// } else { +// console.log("No borders"); +// } + + + +// // Logical Operators +// const country = "United States of America"; +// const continent = "North America"; +// let population = 340.1; +// const isIsland = false; +// const language = "English"; + +// if (language === "English" && population < 50 && !isIsland) { +// console.log(`Sarah can live in ${country}!`); +// } else { +// console.log(`${country} does not meet Sarah's criteria`); +// } + + + +// // The Switch Statement +// const language = "english" +// switch (language) { +// case "chinese": +// case "mandarin": +// console.log("MOST number of native speakers"); +// break +// case "spanish": +// console.log("2nd place in number of native speakers"); +// break +// case "english": +// console.log("3rd place"); +// break +// case "hindi": +// console.log("Number 4"); +// break +// case "arabic": +// console.log("5th most spoken language"); +// break +// default: +// console.log("Great language too"); +// } + + + +// // The Conditional (Ternary) Operator +// const country = "United States of America"; +// const averagePopulation = 33; +// let population = 340.1; + +// console.log(`${country}'s population is ${population > averagePopulation ? "above" : "below"} average`); diff --git a/01-Fundamentals-Part-1/starter/codingChallenges.js b/01-Fundamentals-Part-1/starter/codingChallenges.js index eb0b246c88..8b1e4a7515 100644 --- a/01-Fundamentals-Part-1/starter/codingChallenges.js +++ b/01-Fundamentals-Part-1/starter/codingChallenges.js @@ -1,15 +1,70 @@ // JavaScript Fundamentals Part 1 -// Coding Challenge #1 -const weightMark = 78; -const heightMark = 1.69; +// // Coding Challenge #1 +// const weightMark = 78; +// const heightMark = 1.69; -const weightJohn = 92; -const heightJohn = 1.95; +// const weightJohn = 92; +// const heightJohn = 1.95; -const bmiMark = weightMark / heightMark ** 2; -const bmiJohn = weightJohn / (heightJohn * heightJohn); +// // const weightMark = 95; +// // const heightMark = 1.88; -const markHigherBMI = bmiMark > bmiJohn; +// // const weightJohn = 85; +// // const heightJohn = 1.76; -console.log(bmiMark, bmiJohn, markHigherBMI); +// const bmiMark = weightMark / heightMark ** 2; +// const bmiJohn = weightJohn / (heightJohn * heightJohn); + +// const markHigherBMI = bmiMark > bmiJohn; + +// console.log(bmiMark, bmiJohn, markHigherBMI); + + + +// // Coding Challenge #2 +// if (bmiMark > bmiJohn) { +// console.log(`Mark's BMI (${bmiMark}) is higher than John's (${bmiJohn})!`); +// } else { +// console.log(`John's BMI (${bmiJohn}) is higher than Mark's (${bmiMark})!`); +// } + + + +// // Coding Challenge #3 +// // const scoreDolphins = (96 + 108 + 89) / 3; +// // const scoreKoalas = (88 + 91 + 110) / 3; +// // console.log(scoreDolphins, scoreKoalas); + +// // if (scoreDolphins > scoreKoalas) { +// // console.log("Dolphins win!"); +// // } else if (scoreKoalas > scoreDolphins) { +// // console.log("Koalas win!"); +// // } else { +// // console.log("Draw!"); +// // } + +// // const scoreDolphins = (97 + 112 + 101) / 3; +// // const scoreKoalas = (109 + 95 + 123) / 3; + +// const scoreDolphins = (97 + 112 + 101) / 3; +// const scoreKoalas = (109 + 95 + 106) / 3; +// console.log(scoreDolphins, scoreKoalas); + +// if (scoreDolphins > scoreKoalas && scoreDolphins >= 100) { +// console.log("Dolphins win!"); +// } else if (scoreKoalas > scoreDolphins && scoreKoalas >= 100) { +// console.log("Koalas win!"); +// } else if (scoreDolphins === scoreKoalas && scoreDolphins >= 100) { +// console.log("Draw!"); +// } else { +// console.log("No winner"); +// } + + + +// // Coding Challenge #4 +// const bill = 275; +// const tip = (bill >= 50 && bill <= 300) ? bill * .15 : bill * .20; + +// console.log(`The bill was ${bill}, the tip was ${tip}, and the total value was ${bill + tip}`); diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js new file mode 100644 index 0000000000..9d12123fde --- /dev/null +++ b/01-Fundamentals-Part-1/starter/script.js @@ -0,0 +1,306 @@ +/* +// Basic Operators +const now = 2037; +const ageJonas = now - 1991; +const ageSarah = now - 2020; + +console.log(ageJonas, ageSarah); + +console.log(ageJonas * 2, ageJonas / 10, 2 ** 3); + +const firstName = "Madelyn"; +const lastName = "Romero"; +console.log(firstName + " " + lastName); + +let x = 10 + 5; +x += 10; +x *= 4; +x++; +x--; +x--; + +console.log(x); + + +console.log(ageJonas > ageSarah); +console.log(ageSarah >= 18); + +const isFullAge = ageSarah >= 18; + +console.log(now - 1991 > now - 2018); +*/ + + + +/* +// Operator Precendence +const now = 2037; +const ageJonas = now - 1991; +const ageSarah = now - 2018; + +console.log(now - 1991 > now - 2018); + +let x, y; + +x = y = 25 - 10 - 5; + +console.log(x, y); + +const averageAge = (ageJonas + ageSarah) / 2 +console.log(ageJonas, ageSarah, averageAge); +*/ + + + +/* +// Strings and Template Literals +const firstName = "Madelyn"; +const job = "Software Engineer"; +const birthYear = 1991; +const year = 2037; + +const madelyn = `I'm ` + firstName + " a " + (year - birthYear) + " year old " + job + "!"; +const madelynNew = `I'm ${firstName}, a ${year - birthYear} year old ${job}!` + +console.log(madelyn); +console.log(madelynNew); + +console.log("String with \n\ + multiple \n\ + lines"); + +console.log(`String with + multiple + lines`); +*/ + + + +/* +// Taking Decision: if/else Statements +const age = 18; + +if (age >= 18) { + // console.log("Sarah can start driving license 🥳"); +} else { + const yearsLeft = 18 - age; + // console.log(`Sarah is too young. Wait another ${yearsLeft} years.`); +} + +const birthYear = 1991; +let century; + +if (birthYear <= 2000) { + century = 20; +} else { + century = 21; +} + +// console.log(century); +*/ + + + +/* +// Type Conversion and Coercion +const inputYear = "1991"; +console.log(Number(inputYear), inputYear); + +console.log(Number(inputYear) + 18); + +console.log(Number("Madelyn")); +console.log(typeof NaN); + +console.log(String(23), 23); + + +console.log(`I am ` + 23 + ` years old`); +console.log("23" - "10" - 3); + +console.log(typeof ("1" + 1)); +console.log(typeof (1 + "1")); +*/ + + + +/* +// Truthy and Falsy Values +console.log(Boolean(0)); +console.log(Boolean(undefined)); +console.log(Boolean("Madelyn")); +console.log(Boolean({})); +console.log(Boolean("")); + +const money = 100; +if (money) { + console.log("Don't spend it all"); +} else { + console.log("Get that money"); +} + +let height = 0; +if (height) { + console.log("Yay height is defined"); +} else { + console.log("Height is undefined"); +} +*/ + + + +/* +// Equality Operators +const age = 18; +if (age === 18) { + console.log("You just became an adult (strict)"); +} + +if (age == 18) { + console.log("You just became an adult (loose)"); +} + +const favorite = Number(prompt("What's your favorite number?")); +console.log(typeof (favorite), favorite); + +if (favorite === 13) { + console.log("Cool, 13 is a great number"); +} else if (favorite === 7) { + console.log("7 is also a cool number"); +} else { + console.log("Number is not 13 or 7"); +} + +if (favorite !== 13) { + console.log("Why not 13??"); +} +*/ + + + +/* +// Boolean Logic +const age = 16; +const a = age >= 20; +const b = age < 30; + +console.log(!a); +console.log(a && b); +console.log(a || b); +console.log(!a && b); +console.log(a || !b); +*/ + + + +/* +// Logical Operators +const hasDriversLicense = true; +const hasGoodVision = true; + +console.log(hasDriversLicense && hasGoodVision); +console.log(hasDriversLicense || hasGoodVision); +console.log(!hasDriversLicense); + +const shouldDrive = hasDriversLicense && hasGoodVision; +if (shouldDrive) { + console.log("Sarah can drive"); +} else { + console.log("Someone else should drive"); +} + +const isTired = false; +console.log(hasDriversLicense && hasGoodVision && isTired); + +if (hasDriversLicense && hasGoodVision && !isTired) { + console.log("Sarah can drive"); +} else { + console.log("Someone else"); +} +*/ + + + +/* +// The Switch Statement +const day = "monday"; + +switch (day) { + case "monday": + console.log("Plan course structure"); + console.log("Go to coding meetup"); + break + case "tuesday": + console.log("Prepare theory videos"); + break + case "wednesday": + case "thursday": + console.log("Write code examples"); + break + case "friday": + console.log("Record videos"); + break + case "saturday": + case "sunday": + console.log("Enjoy weekend!"); + break + default: + console.log("Not a valid day"); +} + +if (day === "monday") { + console.log("Plan course structure"); + console.log("Go to coding meetup"); +} else if (day === "tuesday") { + console.log("Prepare theory videos"); +} else if (day === "wednesday" || day === "thursday") { + console.log("Write code examples"); +} else if (day === "friday") { + console.log("Record videos"); +} else if (day === "saturday" || day === "sunday") { + console.log("Enjoy weekend!"); +} else { + console.log("Not a valid day"); +} +*/ + + + +/* +// Statements and Expressions +3 + 4; +1991; +true && false && !false; + +if (23 > 10) { + const str = "23 is bigger"; +} + +console.log(`I'm ${2037 - 1991} years old`); + +// console.log(`${if (23 > 10) { +// const str = "23 is bigger"; +// }}`); +*/ + + + +/* +// The Conditional (Ternary) Operator +const age = 23; + +age >= 18 ? console.log("I like to drink wine") : console.log("Cannot drink yet"); + +const drink = age >= 18 ? "wine" : "water"; + +console.log(`${drink}`); + +let drink2; +if (age >= 18) { + drink2 = "wine" +} else { + drink2 = "water" +} +console.log(`${drink2}`); + +console.log(`I like to drink ${age >= 18 ? "wine" : "water"}`); +*/