From 478521188f28c840995dbcdb5d86917efa20c0c9 Mon Sep 17 00:00:00 2001 From: Dzykas Date: Thu, 31 Aug 2023 06:36:47 +0300 Subject: [PATCH] all i did for day 4 :/, sleepy --- solutions/day-03/index.html | 3 ++- solutions/day-04/index.html | 27 +++++++++++++++++++++++++ solutions/day-04/main.js | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 solutions/day-04/index.html create mode 100644 solutions/day-04/main.js diff --git a/solutions/day-03/index.html b/solutions/day-03/index.html index e1c7bf1..4ca09f0 100644 --- a/solutions/day-03/index.html +++ b/solutions/day-03/index.html @@ -13,7 +13,7 @@ - + +

30DaysOfJavaScript: Day 04

+

Conditionals

+ + +
+
+ + + + \ No newline at end of file diff --git a/solutions/day-04/main.js b/solutions/day-04/main.js new file mode 100644 index 0000000..651e0da --- /dev/null +++ b/solutions/day-04/main.js @@ -0,0 +1,40 @@ +function canDrive() { + let age = parseInt(prompt("Enter your age.")); + + if (age < 18) { + alert("You are not old enough to drive"); + } + else { + alert("You are old enough to drive!") + } +} + +function isOlder() { + let myAge = 17; + let yourAge = parseInt(prompt("How old are you ?")); + + if (yourAge > myAge) { + alert(`You are ${yourAge - myAge} year(s) older than me.`) + } + else { + alert(`I am ${myAge - yourAge} years older than you!`) + } +} + +let a = 4; +let b = 3; + +if (a > b) { + console.log(`${a} is greater than ${b}`); +} + else{ + console.log(`${a} is less than ${b}`); + } + +switch (true) { + case (a > b): + console.log(`${a} is greater than ${b}`); + break; + default: + console.log(`${a} is less than ${b}`); +} \ No newline at end of file