From 815762b046bd1b2ad794a3028dde93625c92d56b Mon Sep 17 00:00:00 2001 From: Mustafa88A Date: Sat, 15 Jul 2023 23:04:37 +0300 Subject: [PATCH 1/4] new file switch and if --- ifStatement.js | 106 +++++++++++++++++++++++++++++++++++++++++++-- index.html | 4 +- switchStatement.js | 36 ++++++++++++++- 3 files changed, 139 insertions(+), 7 deletions(-) diff --git a/ifStatement.js b/ifStatement.js index a1c9316..fdbaba0 100644 --- a/ifStatement.js +++ b/ifStatement.js @@ -13,7 +13,13 @@ 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 = 23; +let minimum=18; +if (userAge >= minimum) +{ + console.log(" the person is old to drive") +} +else{console.log(" the person is not old to drive.")} /************************************************************************************************ Task 2 (if..else Statement): Create a program that checks if a person is an admin, using just if...else statement. @@ -33,6 +39,17 @@ 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 YOUR_NAME = "admin"; +let role= 1212; +let enteredUsername=prompt("give user name"); +if (enteredUsername == YOUR_NAME && role==1212){ +console.log("welcam ") +} +else{ + console.log("I`m sorry") +} + + /************************************************************************************************ Task 3 (if..else Statement): @@ -47,7 +64,19 @@ Steps: - If the number is zero, print a message saying that it is zero. ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW - +let number=prompt("enter namber"); +let float=parseInt(number); + +if ( float >= 0) +{ + console.log("the number is positive ") +} + if ( float <= 0) +{ + console.log("the number is negatine ") + +} +else console.log("is zero "); /************************************************************************************************* Task 4 (if..else Statement): @@ -59,7 +88,16 @@ 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 Age=prompt("ENTRE AGE "); +if (Age >=18) +{ + console.log("Great! You are all set to vote.") +} +else if (Age < 18) { + console.log("You still have time to register to vote") +} +let younger=18-Age; +console.log(younger); /************************************************************************************************* Task 5 (if..else Statement): @@ -122,3 +160,65 @@ Steps: - Use the toFixed() method to format the totalCost to 2 decimal places. *************************************************************************************************/ // TODO: ADD YOUR CODE BELOW +let size = prompt( + "Please select the pizza size: small | medium | large :" +)?.toLowerCase(); + +// Step 2: +let price = 0; +if (size == "small") { + price = 10; +} else if (size == "medium") { + price = 15; +} else if (size == "large") { + price = 20; +} else { + console.log(`please enter a valid size, ${size}`); + size = prompt("Please select the pizza size: small | medium | large :"); +} + +// Step 3: +let toppings = + prompt( + "Please enter the toppings you want, separated by commas: Mushroom, tomato, olive, onion, garlic, pineapple" + )?.split(",") || []; + +// Step 4: +let toppingCost = 0; +if (toppings.length <= 2) { + toppingCost = toppings.length * 2; +} else { + toppingCost = toppings.length * 2 * 0.9; +} + +// Step 5: +let drink = prompt( + "Would you like to add a drink to your order? (yes or no):" +)?.toLowerCase(); + +// Step 6: +let drinkCost = 0; +if (drink === "yes") { + drinkCost = 2; +} + +// Step 7: +let totalCost = price + toppingCost + drinkCost; + +// Step 8: +let discount = 0; +if (toppings.length > 2 && drink) { + discount = totalCost * (15 / 100); + totalCost -= discount; + // OR totalCost *= 0.85; +} else if (toppings.length > 2) { + discount = totalCost * (10 / 100); + totalCost -= discount; +} else if (drink) { + totalCost -= 2; +} + +// Step 9: Wohooooo +console.log( + `Here's your order and the total cost will be: $${totalCost.toFixed(2)}` +); \ No newline at end of file diff --git a/index.html b/index.html index 23aecb3..73bbaed 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ Conditionals - - + + diff --git a/switchStatement.js b/switchStatement.js index b403ed9..0bdd9ad 100644 --- a/switchStatement.js +++ b/switchStatement.js @@ -17,6 +17,20 @@ Steps: 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 +//console.log("Scorpio , Gemini "); +let zodiac=prompt("enter the tower (Scorpio , Gemini)"); + +switch(zodiac) +{ + case 'Scorpio': console.log (" You will have a pleasant surprise today in your career "); + break; + + case 'Gemini': console.log(" You may feel like you are in a rut today. Try doing something out of your comfor"); + break; + + default: + console.log("Sorry, we do not have a horoscope for that sign."); +} /************************************************************************************************ Task 6 (Switch Statement): @@ -29,10 +43,28 @@ Steps: - If the user enters a weather condition that is not recognized by the switch statement, display an error message saying "Sorry, we do not have recommendations for that weather condition." Example: - - What's the weather forecast for today? Rainy - - Recommendations: Wear a waterproof jacket, boots, and bring an umbrella. + - What's the weather forecast for today? Rainy. + - Recommendations: Wear a waterproof jacket, boots, and bring an umbrella ------------------------------------ - What's the weather forecast for today? Sunny - Recommendations: Wear sunscreen, a hat, and sunglasses. ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW +//console.log("Rainy , Sunny , Cloidy , Snowy ") +let weather=prompt("enter the forecasted weather for the day (Rainy , Sunny , Cloidy , Snowy)"); + +switch(weather) +{ +case 'Rainy': console.log(" Wear a waterproof jacket, boots, and bring an umbrella") ; +break; + +case 'Sunny':console.log("Wear sunscreen, a hat, and sunglasses"); +break; + +case 'Cloudy': console.log("Beware, there is a possibility of rain"); +break; + +case 'Snowy': console.log("Wear plenty of clothes, it's cold"); +break; +default :console.log(weather); +} \ No newline at end of file From 005438892e3b3b7a9d79546f7b9fd70af6aeb323 Mon Sep 17 00:00:00 2001 From: Mustafa88A Date: Sun, 16 Jul 2023 17:07:24 +0300 Subject: [PATCH 2/4] new condition in switch --- Zodiac_Signs.md | 2 +- index.html | 2 +- switchStatement.js | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Zodiac_Signs.md b/Zodiac_Signs.md index d94e4c3..d79094c 100644 --- a/Zodiac_Signs.md +++ b/Zodiac_Signs.md @@ -7,7 +7,7 @@ 3. Gemini (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. -4. Cancer (June 21 - July 22): +4.Cancer (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. 5. Leo (July 23 - August 22): diff --git a/index.html b/index.html index 73bbaed..8db02e1 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ Conditionals - + diff --git a/switchStatement.js b/switchStatement.js index 0bdd9ad..b343bec 100644 --- a/switchStatement.js +++ b/switchStatement.js @@ -22,14 +22,37 @@ let zodiac=prompt("enter the tower (Scorpio , Gemini)"); switch(zodiac) { - case 'Scorpio': console.log (" You will have a pleasant surprise today in your career "); + case 'Aries': console.log (" 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; - case 'Gemini': console.log(" You may feel like you are in a rut today. Try doing something out of your comfor"); + case 'Gemini': console.log(" 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 "Taurus": console.log("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 'Cancer':console.log("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; - default: - console.log("Sorry, we do not have a horoscope for that sign."); + case 'Leo':console,log(" 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'Virgo':console.log("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'Libra':console.log("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'Scorpio':console.log("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'Sagittarius':console.log("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"); +break; +case'Capricorn':console.log("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'Aquarius':console.log("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(" 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; + + default: + console.log("Sorry, we do not have a horoscope for that sign."); } /************************************************************************************************ From e72120e68b0545df3205b8f60cb395e6d51971a1 Mon Sep 17 00:00:00 2001 From: Mustafa88A Date: Sun, 16 Jul 2023 17:21:11 +0300 Subject: [PATCH 3/4] switch Task --- switchStatement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/switchStatement.js b/switchStatement.js index b343bec..36c25e6 100644 --- a/switchStatement.js +++ b/switchStatement.js @@ -89,5 +89,5 @@ break; case 'Snowy': console.log("Wear plenty of clothes, it's cold"); break; -default :console.log(weather); +default :console.log("Sorry, we do not have recommendations for that weather condition"); } \ No newline at end of file From 236e604fb62411befb8e21468983bbf6791a47dc Mon Sep 17 00:00:00 2001 From: Mustafa88A Date: Sun, 11 Feb 2024 20:12:46 +0300 Subject: [PATCH 4/4] task if and switch --- ifStatement.js | 65 ++++++++++------------ index.html | 18 +++---- switchStatement.js | 131 ++++++++++++++++++++++++++++++--------------- 3 files changed, 125 insertions(+), 89 deletions(-) diff --git a/ifStatement.js b/ifStatement.js index fdbaba0..b26fa94 100644 --- a/ifStatement.js +++ b/ifStatement.js @@ -13,13 +13,13 @@ 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 = 23; -let minimum=18; -if (userAge >= minimum) -{ - console.log(" the person is old to drive") +let userAge = 24; +let minimum = 18; +if (userAge >= minimum) { + console.log(" the person is old to drive"); +} else { + console.log(" the person is not old to drive."); } -else{console.log(" the person is not old to drive.")} /************************************************************************************************ Task 2 (if..else Statement): Create a program that checks if a person is an admin, using just if...else statement. @@ -39,18 +39,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 YOUR_NAME = "admin"; -let role= 1212; -let enteredUsername=prompt("give user name"); -if (enteredUsername == YOUR_NAME && role==1212){ -console.log("welcam ") -} -else{ - console.log("I`m sorry") +let your_Name = "admin"; +let role = 1212; +let enteredUsername = prompt("give user name"); +if (enteredUsername == your_Name && role == 1212) { + console.log("welcam "); +} else { + console.log("I`m sorry"); } - - /************************************************************************************************ Task 3 (if..else Statement): Write a program that checks if a number is positive, negative or zero, using if...else statement. @@ -64,19 +61,15 @@ Steps: - If the number is zero, print a message saying that it is zero. ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW -let number=prompt("enter namber"); -let float=parseInt(number); - -if ( float >= 0) -{ - console.log("the number is positive ") -} - if ( float <= 0) -{ - console.log("the number is negatine ") +let number = prompt("enter namber"); +let float = parseInt(number); +if (float >= 0) { + console.log("the number is positive "); } -else console.log("is zero "); +if (float <= 0) { + console.log("the number is negatine "); +} else console.log("is zero "); /************************************************************************************************* Task 4 (if..else Statement): @@ -88,15 +81,15 @@ 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 Age=prompt("ENTRE AGE "); -if (Age >=18) -{ - console.log("Great! You are all set to vote.") -} -else if (Age < 18) { - console.log("You still have time to register to vote") +let Age = prompt("ENTRE AGE "); +if (Age >= 18) { + let conformion = confirm("you are volte"); + console.log(conformion); + console.log("Great! You are all set to vote."); +} else if (Age < 18) { + console.log("You still have time to register to vote"); } -let younger=18-Age; +let younger = 18 - Age; console.log(younger); /************************************************************************************************* Task 5 (if..else Statement): @@ -221,4 +214,4 @@ if (toppings.length > 2 && drink) { // Step 9: Wohooooo console.log( `Here's your order and the total cost will be: $${totalCost.toFixed(2)}` -); \ No newline at end of file +); diff --git a/index.html b/index.html index 8db02e1..26aad69 100644 --- a/index.html +++ b/index.html @@ -1,13 +1,13 @@ - - - - + + + + Conditionals - - - - - + + + + + diff --git a/switchStatement.js b/switchStatement.js index 36c25e6..c5c3a35 100644 --- a/switchStatement.js +++ b/switchStatement.js @@ -17,42 +17,77 @@ Steps: 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 -//console.log("Scorpio , Gemini "); -let zodiac=prompt("enter the tower (Scorpio , Gemini)"); +let zodiac = prompt("enter the tower (Scorpio , Gemini)"); +// console.log(zodiac.toLowerCase()); -switch(zodiac) -{ - case 'Aries': console.log (" 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; +switch (zodiac) { + case "Aries": + console.log( + " 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; - case 'Gemini': console.log(" 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 "Taurus": console.log("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 'Cancer':console.log("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( + " 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 "Taurus": + console.log( + "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 'Leo':console,log(" 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( + "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'Virgo':console.log("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'Libra':console.log("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'Scorpio':console.log("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'Sagittarius':console.log("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"); -break; -case'Capricorn':console.log("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'Aquarius':console.log("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(" 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 "Leo": + console.log( + " 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; - default: - console.log("Sorry, we do not have a horoscope for that sign."); + case "Virgo": + console.log( + "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 "Libra": + console.log( + "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 "Scorpio": + console.log( + "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 "Sagittarius": + console.log( + "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" + ); + break; + case "Capricorn": + console.log( + "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 "Aquarius": + console.log( + "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( + " 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; + + default: + console.log("Sorry, we do not have a horoscope for that sign."); } /************************************************************************************************ @@ -74,20 +109,28 @@ Example: ************************************************************************************************/ // TODO: ADD YOUR CODE BELOW //console.log("Rainy , Sunny , Cloidy , Snowy ") -let weather=prompt("enter the forecasted weather for the day (Rainy , Sunny , Cloidy , Snowy)"); +let weather = prompt( + "enter the forecasted weather for the day (Rainy , Sunny , Cloidy , Snowy)" +); -switch(weather) -{ -case 'Rainy': console.log(" Wear a waterproof jacket, boots, and bring an umbrella") ; -break; +switch (weather) { + case "Rainy": + console.log(" Wear a waterproof jacket, boots, and bring an umbrella"); + break; -case 'Sunny':console.log("Wear sunscreen, a hat, and sunglasses"); -break; + case "Sunny": + console.log("Wear sunscreen, a hat, and sunglasses"); + break; -case 'Cloudy': console.log("Beware, there is a possibility of rain"); -break; + case "Cloudy": + console.log("Beware, there is a possibility of rain"); + break; -case 'Snowy': console.log("Wear plenty of clothes, it's cold"); -break; -default :console.log("Sorry, we do not have recommendations for that weather condition"); -} \ No newline at end of file + case "Snowy": + console.log("Wear plenty of clothes, it's cold"); + break; + default: + console.log( + "Sorry, we do not have recommendations for that weather condition" + ); +}