From a0b8452e745b94416b38730e15649a6d4dc12f43 Mon Sep 17 00:00:00 2001 From: haneenjaleel Date: Fri, 14 Jul 2023 02:12:22 +0300 Subject: [PATCH 1/2] solve the task 3 --- ifStatement.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/ifStatement.js b/ifStatement.js index a1c9316..c0c690d 100644 --- a/ifStatement.js +++ b/ifStatement.js @@ -8,12 +8,19 @@ Steps: 3. Write an if statement that checks whether the person's age is greater than or equal to the minimum driving age. - If the person's age is greater than or equal to the minimum driving age, print a message saying that the person is old enough to drive. - If the person's age is less than the minimum driving age, print a message saying that the person is not eligible to get a license yet. - +. Note: You can change the value of the age variable to test different cases. If the person's age is less than the minimum driving age, nothing will be printed. ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW - +let userAge=25; +let minimumDrivingAge=18; +if (userAge>=minimumDrivingAg){ + alert("the person is old enough to drive"); +} +else { + alert("the person is not eligible to get a license yet"); +} /************************************************************************************************ Task 2 (if..else Statement): Create a program that checks if a person is an admin, using just if...else statement. @@ -33,6 +40,14 @@ Steps: - If either of the conditions is false, print the message Hello ${userName}, I'm sorry but it seems you're not authorized to access the restricted area. ***********************************************************/ // TODO: ADD YOUR CODE BELOW +let username = "ahmed"; +let role ="admin"; +let enteredUsername=prompt("enter your name "); +if(username===enteredUsername && role=="admin"){ + console.log("hello ${enterusername}, and you have permission to access the restricted area. "); +}else { + console.log(Hello ${enteredUsername}, I'm sorry but it seems you're not authorized to access the restricted area""); +} /************************************************************************************************ Task 3 (if..else Statement): @@ -47,7 +62,15 @@ Steps: - If the number is zero, print a message saying that it is zero. ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW - +let userNumber = prompt("enter a number"); +let parsedNumber = parseInt(userNumber); +if(parsedNumber>0){ + console.log('the number ${parsedNumber} is positive' ); +} else if(parsedNumber<0){ + console.log('the number ${parsednNumber} is negative'); +}else { + console.log('the number is zero'); +} /************************************************************************************************* Task 4 (if..else Statement): @@ -122,3 +145,5 @@ Steps: - Use the toFixed() method to format the totalCost to 2 decimal places. *************************************************************************************************/ // TODO: ADD YOUR CODE BELOW +let size=prompt("enter pizza size ").toLowerCase(); +let pric \ No newline at end of file From cacdc90703ae38373fe608589ba0be2ba5898322 Mon Sep 17 00:00:00 2001 From: haneenjaleel Date: Sat, 15 Jul 2023 16:51:20 +0300 Subject: [PATCH 2/2] solving the task --- ifStatement.js | 97 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 17 deletions(-) diff --git a/ifStatement.js b/ifStatement.js index c0c690d..a317aa6 100644 --- a/ifStatement.js +++ b/ifStatement.js @@ -40,13 +40,15 @@ Steps: - If either of the conditions is false, print the message Hello ${userName}, I'm sorry but it seems you're not authorized to access the restricted area. ***********************************************************/ // TODO: ADD YOUR CODE BELOW -let username = "ahmed"; -let role ="admin"; -let enteredUsername=prompt("enter your name "); -if(username===enteredUsername && role=="admin"){ - console.log("hello ${enterusername}, and you have permission to access the restricted area. "); -}else { - console.log(Hello ${enteredUsername}, I'm sorry but it seems you're not authorized to access the restricted area""); +let userName = "haneen"; +let role = "Admin"; +let enteredUsername = prompt("Enter your name"); + + +if (enteredUsername == userName && role == "Admin") { + console.log(`Hello ${userName}, and you have permission to access the restricted area`); +}else{ + console.log(`Hello ${userName}, I'm sorry but it seems you're not authorized to access the restricted area`); } /************************************************************************************************ @@ -62,14 +64,16 @@ Steps: - If the number is zero, print a message saying that it is zero. ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW -let userNumber = prompt("enter a number"); -let parsedNumber = parseInt(userNumber); -if(parsedNumber>0){ - console.log('the number ${parsedNumber} is positive' ); -} else if(parsedNumber<0){ - console.log('the number ${parsednNumber} is negative'); -}else { - console.log('the number is zero'); +let number = prompt("Enter a number"); +number = parseInt(number); + + +if (number > 0) { + console.log("The number is positive"); +}else if (number < 0) { + console.log("The number is negative"); +}else{ + console.log("The number is zero"); } /************************************************************************************************* Task 4 (if..else Statement): @@ -83,6 +87,23 @@ Steps: ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW + +let age = prompt("Enter your age"); +age = parseInt(age); + + +if (age >= 18) { + let registered = confirm("Are you registered to vote?"); + if (registered) { + console.log("Great! You are all set to vote."); + }else{ + console.log("You still have time to register to vote."); + } +}else{ + let yearsLeft = 18 - age; + console.log(`You will be eligible to vote in ${yearsLeft} years`); +} + /************************************************************************************************* Task 5 (if..else Statement): @@ -145,5 +166,47 @@ Steps: - Use the toFixed() method to format the totalCost to 2 decimal places. *************************************************************************************************/ // TODO: ADD YOUR CODE BELOW -let size=prompt("enter pizza size ").toLowerCase(); -let pric \ No newline at end of file +let size = prompt("Enter the pizza size (small, medium, or large)"); +size = size.toLowerCase(); + +let price; +if (size == "small") { + price = 10; +}else if (size == "medium") { + price = 15; +}else if (size == "large") { + price = 20; +}else{ + console.log("Invalid pizza size"); +} + + +let toppings = prompt("Enter the toppings you want, separated by commas"); +toppings = toppings.split(","); +let toppingCost; +if (toppings.length <= 2) { + toppingCost = toppings.length * 2; +}else{ + toppingCost = toppings.length * 2 * 0.9; +} + + +let drink = prompt("Would you like to add a drink to your order? (yes or no)"); +drink = drink.toLowerCase(); +let drinkCost; +if (drink == "yes") { + drinkCost = 2; +} + + +let totalCost = price + toppingCost + drinkCost; +if (toppings.length > 2 && drink == "yes") { + totalCost *= 0.85; +}else if (toppings.length > 2) { + totalCost *= 0.9; +}else if (drink == "yes") { + totalCost -= 2; +} + + +console.log(`The total cost of your order is $${totalCost.toFixed(2)}`); \ No newline at end of file