diff --git a/03_Day_Booleans_operators_date/Exercises/scripts/main.js b/03_Day_Booleans_operators_date/Exercises/scripts/main.js index d486293..4c01fe9 100644 --- a/03_Day_Booleans_operators_date/Exercises/scripts/main.js +++ b/03_Day_Booleans_operators_date/Exercises/scripts/main.js @@ -285,7 +285,7 @@ else console.log(`Your first name, ${firstName} is the same length as your family name, ${lastName}`); - //Exercise 12 -- Declare two variables myAge and yourAge and assign them initial values and myAge and yourAge. + //Exercise 12 -- Declare two variables myAge and yourAge and assign them initial values myAge and yourAge let myAge = 250; let yourAge = 25; diff --git a/04_Day_Conditionals/04_day_starter/scripts/main.js b/04_Day_Conditionals/04_day_starter/scripts/main.js index ad0c1eb..ca05cd5 100644 --- a/04_Day_Conditionals/04_day_starter/scripts/main.js +++ b/04_Day_Conditionals/04_day_starter/scripts/main.js @@ -1,3 +1,81 @@ -// this is your main.js script +//Exercises Level 1 -alert('Open the browser console whenever you work on JavaScript') \ No newline at end of file + //Exercise 1 -- Gets user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback telling them how long they have to wait to drive + var age = prompt("Enter your age: "); + let waitTime = 18-age; + console.log("Enter your age: "+age); + + if(age>=18) + console.log("You are old enough to drive"); + else + console.log(`You have ${waitTime} years until you can drive`); + + //Exercise 2 -- Compares the values of myAge and yourAge using if … else. Based on the comparison and logs the result to console stating who is older (me or you). + let myAge = 18; + + if (myAge>age) + console.log('I am '+(myAge-age)+' year(s) older than you.'); + else if(myAge b) + console.log(`${a} is greater than ${b}`); + else + console.log(`${a} is less than ${b}`); + + //Implementation 2 -- Ternary operator + (a>b) + ?console.log(`${a} is greater than ${b}`) //value is true + :console.log(`${a} is less than ${b}`); //value is false + + //Exercise 4 -- Even numbers are divisible by 2 and the remainder is zero. + //How do you check, if a number is even or not using JavaScript? + var input = prompt("Enter a number: "); + console.log(`Enter a number: ${input}`); + + if(input%2 == 0) + console.log("Your number is divisible by 2!"); + else + console.log("Your number is not divisible by 2!"); + +//Exercises Level 2 + + //Exercise 1 -- Write a code which can gives grades to students according to theirs scores + let grade = prompt("Enter grade: "); + console.log(`Enter grade: ${grade}`); + + if(grade>100 || (typeof(grade) == NaN)) + console.log(`${grade} is an invalid grade`); + else if(grade>=80 && grade <=100) + console.log(`Assignment grade: A`); + else if(grade>=70 && grade <=89) + console.log(`Assignment grade: B`); + else if(grade>=60 && grade <=69) + console.log(`Assignment grade: C`); + else if(grade>=50 && grade <=59) + console.log(`Assignment grade: D`); + else + console.log(`Assignment grade: F`); + + //Exercise 2 -- Determines the season of the year given a user entered month + // var enteredMonth = prompt('Enter month: '); + // console.log(`Enter month: ${enteredMonth}`); + // enteredMonth = enteredMonth.toLowerCase(); + + //Exercise 3 -- Checks to see if a day is a weekend day or work day, from a user entered input. + +//Exercises Level 3 + + //Exercise 1 -- + + //Exercise 2 -- \ No newline at end of file