diff --git a/01-Fundamentals-Part-1/coding_challenge_1.js b/01-Fundamentals-Part-1/coding_challenge_1.js new file mode 100644 index 0000000000..224e01b192 --- /dev/null +++ b/01-Fundamentals-Part-1/coding_challenge_1.js @@ -0,0 +1,47 @@ +/* +Mark and John are trying to compare their BMI (Body Mass Index), which is +calculated using the formula: +BMI = mass / height ** 2 = mass / (height * height) (mass in kg +and height in meter). +Your tasks: +1. Store Mark's and John's mass and height in variables +2. Calculate both their BMIs using the formula (you can even implement both +versions) +3. Create a Boolean variable 'markHigherBMI' containing information about +whether Mark has a higher BMI than John. +Test data: +§ Data 1: Marks weights 78 kg and is 1.69 m tall. John weights 92 kg and is 1.95 +m tall. +§ Data 2: Marks weights 95 kg and is 1.88 m tall. John weights 85 kg and is 1.76 +m tall. +*/ + +// let massMark = 78; +// let massJohn = 92; + +// let heightMark = 1.69; +// let heightJohn = 1.95; + +// let bmiMark = massMark / (heightMark ** 2); +// let bmiJohn = massJohn / (heightJohn ** 2); + +// console.log(bmiJohn); +// console.log(bmiMark); + +// let markHigherBMI = bmiMark < bmiJohn; + +// console.log(bmiMark, bmiJohn, markHigherBMI); + + +let massMark = 95; +let massJohn = 85; + +let heightMark = 1.88; +let heightJohn = 1.76; + +let bmiMark = massMark / heightMark ** 2; +let bmiJohn = massJohn / heightJohn ** 2; + +let markHigherBMI = bmiMark < bmiJohn; + +console.log(bmiMark, bmiJohn, markHigherBMI); \ No newline at end of file diff --git a/01-Fundamentals-Part-1/starter/index.html b/01-Fundamentals-Part-1/starter/index.html index 59529c7923..f44acb556b 100755 --- a/01-Fundamentals-Part-1/starter/index.html +++ b/01-Fundamentals-Part-1/starter/index.html @@ -25,5 +25,7 @@

JavaScript Fundamentals – Part 1

+ + diff --git a/01-Fundamentals-Part-1/starter/script.js b/01-Fundamentals-Part-1/starter/script.js new file mode 100644 index 0000000000..7c86759f6d --- /dev/null +++ b/01-Fundamentals-Part-1/starter/script.js @@ -0,0 +1,159 @@ +/* +let js = 'amazing'; +console.log(40 + 8 + 23 - 10); + +console.log('Jonas'); +console.log(23); + +let firstName = "Matilda"; + +console.log(firstName); +console.log(firstName); +console.log(firstName); + +// Variable name conventions +let jonas_matilda = "JM"; +let $function = 27; + +let person = 'jonas'; +let PI = 3.1415; + +let myFirstJob = 'Programmer'; +let myCurrentJob = 'Teacher'; + +let job1 = 'programmer'; +let job2 = 'teacher'; + +console.log(myFirstJob); + + +let javascriptIsFun = true; +console.log(javascriptIsFun); + +console.log(typeof true); +console.log(typeof javascriptIsFun); +console.log(typeof 23); +console.log(typeof "Jonas"); + +javascriptIsFun = "YES!"; +console.log(typeof javascriptIsFun); + +let year; +console.log(year); +console.log(typeof year); + +year = 1991; +console.log(typeof year); + +console.log(typeof null); + + + +let age= 30; +age = 31; + +const birthYear = 1991; +//birthYear = 1990; + +const job; + +var job = 'programmer'; +job = 'teacher'; + +lastName = 'Schmedtmann'; +console.log(lastName); +//Basic Operators +//Math operators +const now = 2037; +const ageJonas = now - 1991; +const ageSarah = now - 2018; +console.log(ageJonas, ageSarah); + +console.log(ageJonas * 2, ageJonas / 10, 2 ** 3); +// 2 ** 3 means 2 to the power of 3 = 2*2*2 + +const firstName = 'Jonas'; +const lastName = 'Schmedtmann'; +console.log(firstName + ' ' + lastName); + + +//Assignment operators +let x = 10 + 5; // 15 +x += 10; // x = x + 10 = 25 +x *= 4; // x = x * 4 = 100 +x++; // x = x + 1 +x--; +console.log(x); + +// Comparison operators +console.log(ageJonas > ageSarah); // >, <, >=, <= +console.log(ageSarah >= 18); + +const isFullAge = ageSarah >= 18; + +console.log(now - 1991 > now - 2018); + + +//Operator Precedence +const now = 2037; +const ageJonas = now - 1991; +const ageSarah = now - 2018; + +console.log(now - 1991 > now - 2018); + +console.log(25 - 10 - 5); + +let x, y; +x = y = 25 - 10 - 5; // x = y = 10 +console.log(x , y); + +const averageAge = (ageJonas + ageSarah) / 2; +console.log(ageJonas, ageSarah,averageAge); + + +//Strings and template literals +const firstName = 'Jonas'; +const job = 'teacher'; +const birthYear = 1991; +const year = 2037; + +const jonas = "I'm " + firstName + ', a ' + (year - birthYear) + ' years old' + job + '!'; +console.log(jonas); + +const jonasNew = `I'm ${firstName}, a ${year - birthYear} year old ${job}`; +console.log(jonasNew); + +console.log(`Just a regular string...`); + +console.log('String with \n\ +multiple \n\ +lines'); + +console.log(`String +multiple +lines`); +*/ + +// Taking decisions with if/else statements +const age = 15; + + +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 +const birthYear = 1998; + +let century; + +if(birthYear <= 2000){ + century = 20; +} else { + century = 21; +} +console.log(century); \ No newline at end of file