From a5c59c522183442a4777cc2e912cc11c690fd664 Mon Sep 17 00:00:00 2001 From: Stelladelmar Date: Thu, 30 Mar 2023 00:47:30 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8C=F0=9F=8F=BC1st?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 17 +++++++ mandatory/1-fix-functions.js | 10 ++-- mandatory/2-function-creation.js | 81 +++++++++++++++++++++++++++----- 3 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..cb498e8c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/mandatory/2-function-creation.js" + } + ] +} \ No newline at end of file diff --git a/mandatory/1-fix-functions.js b/mandatory/1-fix-functions.js index 6323604f..20c96808 100644 --- a/mandatory/1-fix-functions.js +++ b/mandatory/1-fix-functions.js @@ -10,9 +10,7 @@ */ -function getMood() { - let isHappy = true; - +function getMood(isHappy) { if (isHappy) { return "I am happy"; } else { @@ -21,14 +19,14 @@ function getMood() { } function greaterThan10(num) { - let isBigEnough; - - if (isBigEnough) { + + if (num > 10) { return "num is greater than 10"; } else { return "num is not big enough"; } } +//greaterThan10(11); /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index d4590920..d0712915 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -4,7 +4,15 @@ 1. the user should be 18 or older 2. the user must be logged in */ -function isAcceptableUser(userAge, isLoggedIn) {} +let userAge = 19; +let isLoggedIn = true; +function isAcceptableUser(userAge, isLoggedIn){ + if (userAge >= 18 && isLoggedIn === true){ + return true; + } else { + return false; + } +} /* Complete the function to apply discount percent based on how much is totalPrice in user cart. @@ -12,21 +20,44 @@ function isAcceptableUser(userAge, isLoggedIn) {} - When the total price is less than 200, a 5% discount should be applied The function should return the new price to be paid (e.g. if the totalPrice is 150, a 5% discount - is applieds and 142.5 should be returned) + is applied and 142.5 should be returned) */ - -function applyDiscount(totalPrice) {} - +//let totalPrice = 150; +function applyDiscount(totalPrice) { + if (totalPrice >200){ + return (totalPrice - totalPrice * 0.01); + } else if ( totalPrice <200){ + return (totalPrice - totalPrice *0.1); + } +} +// +//console.log(applyDiscount(220)); /* Complete the function to print to the console the odd numbers between 1 and limit (use a while loop): */ -function printOddNumbers(limit) {} - +//function printOddNumbers(limit) {} +let limit = 0; +function printOddNumbers(limit) { +while (limit <= 10){ + console.log(limit); +} limit = limit + 1; +} /* Complete the buyTwoGetTheCheapestFree function: if user buys two items, the cheapest item will be free! The function should return the price to be paid once the discount is applied. */ -function buyTwoGetTheCheapestFree(price1, price2) {} +let price1 = 700; +let price2 = 500; +function buyTwoGetTheCheapestFree(price1, price2) { + if(price1 > price2){ + return price1; + } else if (price2 > price1){ + return price2; + } + //console.log("price is"); + + } + /* Complete the function to determine if it is suitable for a person to register based on their age! @@ -34,18 +65,42 @@ function buyTwoGetTheCheapestFree(price1, price2) {} - if the person is older than 12 and younger than 90 it should return "You Can Register" - if the person is 90 or older it should return "You Don't Need To Register" */ -function canRegister(age) {} +// && => and +// || => or +// ! => not 5!== 6 (or if is not equal to) + +function canRegister(age) { + if (age <= 12 ){ + return "You Are Too Young To Register"; + } else if (age < 90 && age > 12 ) { + return "You Can Register"; } + else if (age >= 90 ){ + return "You Don't Need To Register"; } + + } + //console.log("You are too young to register") + /* - Complete the function so that it prints out to the console numbers in reverse order starting at - number and going down to 1 (e.g. if number was 3, it would print: + Complete the function so that it prints out to the + console numbers in reverse order starting at + number and going down to 1 (e.g. if number was + 3, it would print: 3 2 1 ) */ - -function countReverse(number) {} +//while loop +//from 7 to 1 +let number = 7; +function countReverse(number) { + while (number >= 10 ){ + console.log(number); + number = number--; + } + +} /* ======= TESTS - DO NOT MODIFY ===== */