Skip to content
Open
Show file tree
Hide file tree
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
81 changes: 78 additions & 3 deletions ifStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Note:
You can change the value of the age variable to test different cases.
************************************************************************************************/
// TODO: ADD YOUR CODE BELOW
// let userAge=37;
// let minDrivingAge=18;
// if (userAge >= minDrivingAge){
// console.log("You are old enough to drive.");
// } else{
// console.log("you are ot eligible to get a license yet.");}

/************************************************************************************************
Task 2 (if..else Statement): (15 pts) 👨🏽‍💼
Expand All @@ -33,7 +39,14 @@ Steps:
- If either of the conditions is false, print the message Hello ${enteredUsername}, I'm sorry but it seems you're not authorized to access the restricted area.
***********************************************************/
// TODO: ADD YOUR CODE BELOW

// let userName="mehdi";
// let role="Admin";
// let enteredUsername=prompt("Enter your name")
// if (userName.toLowerCase==="mehdi" && role==="Admin"){
// console.log(`Hello ${enteredUsername}, 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): (20 pts) 🔢
Write a program that checks if a number is positive, negative or zero, using if...else statement.
Expand All @@ -47,7 +60,14 @@ Steps:
- If the number is zero, print a message saying that it is zero.
************************************************************************************************/
// TODO: ADD YOUR CODE BELOW

// let num=prompt("Enter a number");
// if (parseInt(num)>0){
// console.log("The number is positive");
// } else if(parseInt(num)<0){
// console.log("The number is negative");
// } else {
// console.log("The number is zero");
// }
/*************************************************************************************************
Task 4 (Nested if..else Statement): (15 pts) 👵🏼

Expand All @@ -59,7 +79,17 @@ Steps:
- If the user is younger than 18, the program should calculate how many years are left until they turn 18 and print the message "You will be eligible to vote in X years", where X is the number of years left.
************************************************************************************************/
// TODO: ADD YOUR CODE BELOW

// let userAge=prompt("Enter your age")
// if (parseInt(userAge)>=18){
// const confirmation = confirm("would you like to continue to the voting part or not");
// if(confirmation ==true){
// console.log("Great! You are all set to vote.");
// } else {
// console.log("Why did you waste my time then? 😀") };
// } else{
// let leftYears=18-userAge
// console.log(`You will be eligible to vote in ${leftYears} years`);
// }
/*************************************************************************************************
Task 5 (if..else Statement): (100 pts) 🍕

Expand Down Expand Up @@ -122,3 +152,48 @@ Steps:
- Use the toFixed() method to format the totalCost to 2 decimal places.
*************************************************************************************************/
// TODO: ADD YOUR CODE BELOW
// 1
let pizzaSize=prompt("Enter your pizza size 'small or medium or large'");
let size=pizzaSize.toLowerCase();
// 2
let price;
if (size==="small"){
price=10;
}else if(size==="medium"){
price=20;
}
else if(size==="large"){
price=30;
} else{
console.log("Please select a valid size");
}
// 3
let pizzaToppings=prompt("select the toppings");
let toppings=pizzaToppings.split(' ')
// 4
let toppingCost;
if (toppings.length<=2){
toppingCost=toppings.length*2
} else if(toppings.length>2){
toppingCost=toppings.length*2*0.9
}
// 5
let ask =prompt("would you like a drink? write yes or no")
let drink=ask.toLowerCase()
// 6
let drinkCost;
if (drink==="yes"){
drinkCost=2;
} else{ drinkCost=0}
// 7
let totalCost=price+toppingCost+drinkCost;
// 8
if (toppings.length>2 && drink==="yes"){
totalCost= totalCost-0.15;
} else if (toppings.length>2){
totalCost= totalCost-0.1;
} else if (drink==="yes"){
totalCost=totalCost-2;
}
// 9
console.log(`The total cost of your order is ${totalCost.toFixed(2)}`);
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<script src="./ifStatement.js"></script>
<!-- <script src="./switchStatement.js"></script> -->
<!-- <script src="./switchStatement.js"></script> -->
</body>
</html>
117 changes: 117 additions & 0 deletions switchStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,74 @@ Steps:
*Note: Check the file called "Zodiac_Signs.md" to find the list of horoscope messages.*
************************************************************************************************/
// TODO: ADD YOUR CODE BELOW
// let zodiacSign=prompt("Enter your zodiac");
// zodiacSign=zodiacSign.toLowerCase()

// switch (zodiacSign){
// case "aquarius":
// console.log(`(January 20 - February 18):
// Horoscope: Your humanitarian side is in the spotlight today, Aquarius. Engage in activities that promote social causes and make a positive impact. Connect with like-minded individuals and share your innovative ideas.`);
// break;

// case "pisces":
// console.log(`(February 19 - March 20):
// Horoscope: Your sensitivity and intuition are heightened today, Pisces. Pay attention to your dreams and emotions, as they may hold important messages for you. Take some time for self-reflection and introspection.`);
// break;

// case "capricorn":
// console.log(`(December 22 - January 19):
// Horoscope: It's time to focus on your career goals, Capricorn. Set clear objectives and work diligently towards achieving them. Your hard work and determination will pay off in the long run.`);
// break;

// case "sagittarius":
// console.log(`(November 22 - December 21):
// Horoscope: You're in the mood for adventure, Sagittarius. Plan a trip or explore new possibilities. Your optimism and enthusiasm will inspire others, and you may learn something new.`);

// case "scorpio":
// console.log(`(October 23 - November 21):
// Horoscope: Your intuition is heightened today, Scorpio. Trust your instincts and delve into your emotions. Explore your subconscious mind and gain insights into your inner workings.`);
// break;

// case "libra":
// console.log(`(September 23 - October 22):
// Horoscope: Your diplomacy and charm are in full force today, Libra. Use your skills to resolve conflicts and bring harmony to your relationships. Seek balance and fairness in all your interactions.`);
// break;

// case "virgo":
// console.log(`(August 23 - September 22):
// Horoscope: It's a good day for organizing and decluttering, Virgo. Clean up your physical space and tidy up your thoughts. Focus on practical matters and set achievable goals.`);
// break;

// case "leo":
// console.log(`(July 23 - August 22):
// Horoscope: Your creativity is on fire today, Leo. Express yourself through your artistic pursuits and let your inner child come out to play. Your confidence and charisma will attract attention.
// `);
// break;

// case "cancer":
// console.log(`(June 21 - July 22):
// Horoscope: It's time to take care of yourself, Cancer. Pay attention to your emotional well-being and prioritize self-care. Take a break from your usual routine and indulge in some self-nurturing activities.`);
// break;

// case "gemini":
// console.log(`(May 21 - June 20):
// Horoscope: Your social calendar is likely to be full today, Gemini. You're in the mood for socializing and networking. Make new connections and engage in stimulating conversations. Keep an open mind.`);
// break;

// case "taurus":
// console.log(`(April 20 - May 20):
// Horoscope: It's a good day to focus on your financial matters, Taurus. Take a look at your budget and make any necessary adjustments. Avoid impulsive spending and save for the future.
// `);
// break;

// case "aries":
// console.log(`(March 21 - April 19):
// Horoscope: You're feeling bold and energetic today, Aries! Take advantage of this burst of energy and tackle any challenges that come your way. Your determination and confidence will help you achieve your goals.`);
// break;

// default:
// console.log("Sorry, we do not have a horoscope for that sign.");
// }
/************************************************************************************************
Task 6 (Switch Statement): (20 pts)
Create a program that helps you decide what to wear based on the weather forecast for the day.
Expand All @@ -39,3 +106,53 @@ Example:
*Note: Check the file called "Clothing_Recommendations.md" to find the list of weather forecasts and their corresponding clothing recommendations.*
************************************************************************************************/
// TODO: ADD YOUR CODE BELOW
let weather=prompt("Enter the condition of the weather:")
weather=weather.toLowerCase()

switch (weather){
case "sunny":
console.log(`Recommendations:

1. Choose lightweight cotton, linen, rayon, chambray, or silk fabrics for breathability and comfort.
2. Opt for light colors and loose-fitting styles to reflect heat and allow air circulation.
3. Wear appropriate sun protection, such as a wide-brimmed hat and sunglasses, and apply sunscreen.
4. Stay hydrated and enjoy the sunny weather in comfortable and breathable clothes!`);
break;

case "rainy":
console.log(`ecommendations:

1. Choose waterproof or water-resistant fabrics like polyester, nylon, or Gore-Tex for maximum protection.
2. Synthetic blends are also a good option for their water-repelling properties.
3. Avoid absorbent fabrics like cotton or silk that can become heavy when wet.
4. Consider treated fabrics that are coated with a water-repellent finish.
5. Pair rain gear with appropriate footwear and rain accessories as needed to stay dry in rainy weather.`);
break;

case "cloudy":
console.log(`Recommendations:

1. Layer with lightweight knits, fleece, or flannel for easy adjustment to changing temperatures.
2. Choose breathable fabrics like cotton, bamboo, or modal for comfort.
3. Opt for moisture-wicking fabrics like polyester or nylon to stay dry in light drizzle or humidity.
4. Consider fabrics with stretch for flexibility and comfort during activities.
5. Don't forget to have a light jacket or coat made of weather-resistant materials for added protection from wind or light rain.
Being prepared with versatile fabrics and layering options can help you stay comfortable in changing weather conditions during cloudy days!
`);
break;

case "snowy":
console.log(`Recommendations:

1. Insulating fabrics like fleece, down, or synthetic insulation for warmth.
2. Waterproof or water-resistant fabrics like Gore-Tex, nylon, or polyester to stay dry.
3. Moisture-wicking fabrics like polyester or merino wool to keep you dry.
4. Layering fabrics such as thermal knits, fleece, or merino wool for insulation.
5. Windproof fabrics like nylon or softshell materials for protection from wind chill.
Prioritize warmth, insulation, moisture management, and wind protection when dressing for snowy weather, and be sure to layer appropriately to stay warm and dry in snowy conditions!
`);
break;

default:
console.log("Sorry, we do not have recommendations for that weather condition.");
}