From 765c6a1b39f7ae49cb04f86ec68c02cdd966dc83 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:41:42 +0000 Subject: [PATCH 1/7] javaScript-core-1-Coursework-week2 answer 2 mandatory --- mandatory/1-fix-functions.js | 8 ++++---- mandatory/2-function-creation.js | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mandatory/1-fix-functions.js b/mandatory/1-fix-functions.js index 6323604f..8a006ac3 100644 --- a/mandatory/1-fix-functions.js +++ b/mandatory/1-fix-functions.js @@ -10,8 +10,8 @@ */ -function getMood() { - let isHappy = true; +function getMood(isHappy) { + // let isHappy = true; if (isHappy) { return "I am happy"; @@ -20,8 +20,8 @@ function getMood() { } } -function greaterThan10(num) { - let isBigEnough; +function greaterThan10(isBigEnough) { + //let isBigEnough; if (isBigEnough) { return "num is greater than 10"; diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index d4590920..5358d511 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -4,7 +4,13 @@ 1. the user should be 18 or older 2. the user must be logged in */ -function isAcceptableUser(userAge, isLoggedIn) {} +function isAcceptableUser(userAge, isLoggedIn) { + if(userAge>= 18 && isLoggedIn){ + return true + }else{ + return false + } +} /* Complete the function to apply discount percent based on how much is totalPrice in user cart. @@ -15,7 +21,13 @@ function isAcceptableUser(userAge, isLoggedIn) {} is applieds and 142.5 should be returned) */ -function applyDiscount(totalPrice) {} +function applyDiscount(totalPrice) { + if (totalPrice>200){ + return totalPrice-(totalPrice * 0.10) + }else { + return totalPrice-(totalPrice *0.50) + } +} /* Complete the function to print to the console the odd numbers between 1 and limit (use a while loop): From c28ca4dc2a481563bcef6faddc3d7249bcac60e6 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Fri, 24 Feb 2023 18:03:55 +0000 Subject: [PATCH 2/7] Update 1-fix-functions.js finished i-fix-Function --- mandatory/1-fix-functions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mandatory/1-fix-functions.js b/mandatory/1-fix-functions.js index 8a006ac3..35f6e3dc 100644 --- a/mandatory/1-fix-functions.js +++ b/mandatory/1-fix-functions.js @@ -23,7 +23,7 @@ function getMood(isHappy) { function greaterThan10(isBigEnough) { //let isBigEnough; - if (isBigEnough) { + if (isBigEnough > 10) { return "num is greater than 10"; } else { return "num is not big enough"; From ee7ee5e69fdace58cb1ccbcc46980121699830ad Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Sun, 26 Feb 2023 14:13:44 +0000 Subject: [PATCH 3/7] javaScript-Core-1-Coursework-Week2 update exercise mandatory --- mandatory/2-function-creation.js | 41 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index 5358d511..4937af5c 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -25,20 +25,40 @@ function applyDiscount(totalPrice) { if (totalPrice>200){ return totalPrice-(totalPrice * 0.10) }else { - return totalPrice-(totalPrice *0.50) + return totalPrice-(totalPrice *0.05) } } /* 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 numberOfLoops= 1 + while (numberOfLoops <= limit) { + console.log(numberOfLoops); + numberOfLoops = numberOfLoops + 2; +} +} /* 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) {} + + +function buyTwoGetTheCheapestFree(price1, price2) { +// let price1 = 700 +// let price2 = 500 +if(price1>price2) { + return price1 +}else{ + return price2 +} + + +} + /* Complete the function to determine if it is suitable for a person to register based on their age! @@ -46,7 +66,16 @@ 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) {} +function canRegister(age) { +if(age<=12){ +return "You Are Too Young To Register" +} +else if (age> 12 && age<90){ +return "You Can Register" +}else { + return "You Don't Need To Register" +} +} /* Complete the function so that it prints out to the console numbers in reverse order starting at @@ -57,7 +86,9 @@ function canRegister(age) {} ) */ -function countReverse(number) {} +function countReverse(number) { + console.log() +} /* ======= TESTS - DO NOT MODIFY ===== */ From f34c80242d11bcc70a3d25dc3c76154d77741291 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:39:58 +0000 Subject: [PATCH 4/7] javaScript-Core-1-Coursework-Week2 update --- mandatory/2-function-creation.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index 4937af5c..cd5f7b87 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -51,9 +51,9 @@ function buyTwoGetTheCheapestFree(price1, price2) { // let price1 = 700 // let price2 = 500 if(price1>price2) { - return price1 + return price1; }else{ - return price2 + return price2; } @@ -72,13 +72,13 @@ return "You Are Too Young To Register" } else if (age> 12 && age<90){ return "You Can Register" -}else { +}else (age > 90);{ return "You Don't Need To Register" } } /* - Complete the function so that it prints out to the console numbers in reverse order starting at + Complete the 1 (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 @@ -86,10 +86,23 @@ return "You Can Register" ) */ +/*function countReverse(number) { + number = number + ""; + console.log() +}*/ function countReverse(number) { - console.log() + for(let i= number; i>0; i--){ + console.log(i) + } } +/*console.log(reverseNum(1234567));*/ + + + + + + /* ======= TESTS - DO NOT MODIFY ===== */ describe("isAcceptableUser", () => { From 2b546190bb36ad5736fb60d7701edaa8e6cb89fd Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Wed, 1 Mar 2023 01:21:12 +0000 Subject: [PATCH 5/7] javascript-core-1-coursework-week2 update --- mandatory/2-function-creation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index cd5f7b87..b4f7425a 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -91,9 +91,9 @@ return "You Can Register" console.log() }*/ function countReverse(number) { - for(let i= number; i>0; i--){ +for(let i=number; i>0; i--){ console.log(i) - } +} } /*console.log(reverseNum(1234567));*/ From 61d2487f8d1010c409379f375e63ee0ec24c4067 Mon Sep 17 00:00:00 2001 From: Danny Romero <108970600+Elenar9@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:33:40 +0000 Subject: [PATCH 6/7] Javascript-core-1-coursework-week2 update 2-function-creation --- mandatory/1-fix-functions.js | 2 +- mandatory/2-function-creation.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mandatory/1-fix-functions.js b/mandatory/1-fix-functions.js index 35f6e3dc..dd91aaf1 100644 --- a/mandatory/1-fix-functions.js +++ b/mandatory/1-fix-functions.js @@ -21,7 +21,7 @@ function getMood(isHappy) { } function greaterThan10(isBigEnough) { - //let isBigEnough; + //let isBigEnough = true; if (isBigEnough > 10) { return "num is greater than 10"; diff --git a/mandatory/2-function-creation.js b/mandatory/2-function-creation.js index b4f7425a..a5636970 100644 --- a/mandatory/2-function-creation.js +++ b/mandatory/2-function-creation.js @@ -23,7 +23,7 @@ function isAcceptableUser(userAge, isLoggedIn) { function applyDiscount(totalPrice) { if (totalPrice>200){ - return totalPrice-(totalPrice * 0.10) + return totalPrice-(totalPrice * 0.1) }else { return totalPrice-(totalPrice *0.05) } @@ -35,7 +35,7 @@ function applyDiscount(totalPrice) { function printOddNumbers(limit) { let numberOfLoops= 1 - while (numberOfLoops <= limit) { + while (numberOfLoops price2) { return price1; -}else{ +}else if (price1 < price2) return price2; } -} - /* Complete the function to determine if it is suitable for a person to register based on their age! @@ -72,7 +70,7 @@ return "You Are Too Young To Register" } else if (age> 12 && age<90){ return "You Can Register" -}else (age > 90);{ +}else { return "You Don't Need To Register" } } @@ -90,12 +88,20 @@ return "You Can Register" number = number + ""; console.log() }*/ + function countReverse(number) { for(let i=number; i>0; i--){ console.log(i) } } +// +// function repeatStr (n, s) { +// var str=""; +// for(var i=0; i < n; i++) +// str+=s; +// return str; +// } /*console.log(reverseNum(1234567));*/ From aa4a6a4ba002bbe2fd320bfa81a2b07e7b20a0c1 Mon Sep 17 00:00:00 2001 From: Elenar9 Date: Thu, 30 Mar 2023 13:05:45 +0100 Subject: [PATCH 7/7] Update 1-factorial.js update exercise 1 --- extra/1-factorial.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extra/1-factorial.js b/extra/1-factorial.js index da9f8e6c..f5aae045 100644 --- a/extra/1-factorial.js +++ b/extra/1-factorial.js @@ -9,7 +9,13 @@ */ function factorial(input) { - // TODO + /*0! =1, 1! =1*/ + if (input>0 && input<=1) { + return 1; + }else { + return input * factorial(input - 1); + } + } /* ======= TESTS - DO NOT MODIFY ===== */