Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
17 changes: 17 additions & 0 deletions .vscode/launch.json
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"
}
]
}
10 changes: 4 additions & 6 deletions mandatory/1-fix-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

*/

function getMood() {
let isHappy = true;

function getMood(isHappy) {
if (isHappy) {
return "I am happy";
} else {
Expand All @@ -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 ===== */

Expand Down
81 changes: 68 additions & 13 deletions mandatory/2-function-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

}

/*
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);

Choose a reason for hiding this comment

The 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 😉
0.01 would be 1% and 0.1 would be a 10%, but where is our 5% discount? 😜

Copy link
Author

Choose a reason for hiding this comment

The 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;
}

Choose a reason for hiding this comment

The 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");
Copy link

@kwebster77 kwebster77 Mar 31, 2023

Choose a reason for hiding this comment

The 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"; }

}

Choose a reason for hiding this comment

The 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 ){

Choose a reason for hiding this comment

The 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:

for (let i = number; i > 0; i--)

console.log(number);
number = number--;
}

}

/* ======= TESTS - DO NOT MODIFY ===== */

Expand Down