Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 90 additions & 2 deletions ifStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -33,6 +40,16 @@ 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 = "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`);
}

/************************************************************************************************
Task 3 (if..else Statement):
Expand All @@ -47,7 +64,17 @@ Steps:
- If the number is zero, print a message saying that it is zero.
************************************************************************************************/
// TODO: ADD YOUR CODE BELOW
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):

Expand All @@ -60,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):

Expand Down Expand Up @@ -122,3 +166,47 @@ Steps:
- Use the toFixed() method to format the totalCost to 2 decimal places.
*************************************************************************************************/
// TODO: ADD YOUR CODE BELOW
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)}`);