-
-
Notifications
You must be signed in to change notification settings - Fork 437
London10-StellaDelMar_RodriguezFernandez-JavaScript-Core-1-Coursework-Week2 #457
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/mandatory/2-function-creation.js" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,48 +4,103 @@ | |
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. | ||
- When the total price is greater than 200, a 10% discount should be applied | ||
- 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice job with the if statement! Just might want to check your maths on this one 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I understand 😅 |
||
} 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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we might have another infinite loop here (docs here). Maybe have a quick review on how while loops work? they can be a bit tricky. |
||
/* | ||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice job using an if statement here. LGTM! (here is the meaning if this acronym!) |
||
|
||
} | ||
|
||
|
||
/* | ||
Complete the function to determine if it is suitable for a person to register based on their age! | ||
- if the person is 12 or younger it should return "You Are Too Young To Register" | ||
- 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"; } | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! nice work on this one 🎉 |
||
//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 ){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So for this one, using a while loop where will probably result in an infinite loop (more on this here), if the number is greater than 10. Otherwise, this will not run as the number would be less than 10 (for example in your number = 7 example, this wouldn't return anything because the number is less than 10). You might want to think about using a for loop here:
|
||
console.log(number); | ||
number = number--; | ||
} | ||
|
||
} | ||
|
||
/* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one!