-
-
Notifications
You must be signed in to change notification settings - Fork 438
London10-Onur-Atas-JavaScript-Core-1-Coursework-Week2 #464
base: main
Are you sure you want to change the base?
Conversation
let isHappy = mood; | ||
|
||
if (isHappy) { | ||
if (isHappy === true) { |
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.
Well done finding a valid solution, but a few notes:
Do you need to reassign "mood" here?
Also, on line 16, is there a shorter way to check if a variable is true?
let isBigEnough = num; | ||
|
||
if (isBigEnough) { | ||
if (isBigEnough > 10) { |
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.
Do you need to reassign "num" here?
function isAcceptableUser(userAge, isLoggedIn) { | ||
if (userAge >= 18 && isLoggedIn === true) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
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.
Do you need to explicitly compare "isLoggedIn" to true to achieve this result?
Should the else block start on a new line here? Refer back to the formatting in the 1-fix-function.js file.
function applyDiscount(totalPrice) { | ||
if (totalPrice >= 200) { | ||
return totalPrice * 0.9; | ||
} | ||
else { | ||
return totalPrice * 0.95; | ||
|
||
/* | ||
} | ||
|
||
|
||
|
||
} |
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.
Read the requirements carefully, should you be checking if the totalPrice is greater or equal to 200?
Also, the else block should not be on a new line
function printOddNumbers(limit) { | ||
|
||
for (let i = 0; i <= limit; i++) { | ||
if (i % 2 === 1) { | ||
console.log(i); | ||
} | ||
} | ||
|
||
|
||
} |
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.
Ensure you do not leave lots of unnecessary whitespace in functions.
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.
Well done finding an alternative solution, but also ensure you read the requirements carefully, it asks for a while loop to be used.
function buyTwoGetTheCheapestFree(price1, price2) { | ||
if (price1 > price2) { | ||
return price1; | ||
} | ||
else { | ||
return price2; | ||
|
||
} | ||
|
||
|
||
} |
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.
Ensure you do not leave lots of unnecessary whitespace in functions.
Also, the else block should not be on a newline.
function countReverse(number) { | ||
for (let i = number; i >= 1; i--) { | ||
console.log(i); | ||
} | ||
} |
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 work
function canRegister(age) { | ||
if (age <= 12) { | ||
return "You Are Too Young To Register"; | ||
} else if (age < 90) { | ||
return "You Can Register"; | ||
} else { | ||
return "You Don't Need To Register"; | ||
} | ||
} |
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 work
Overall good job on the solutions, well done. For future learning, maybe look into how to use Ternary Operators in JS. They can be useful when writing simple conditions as they are cleaner and easier to read when used appropriately. For example, the getMood function in the 1-fix-functions.js file can be rewritten to use a ternary operator. Standard if-else :
With a ternary operator expression:
Here is a link to find examples of this type of expression: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator |
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.md
in the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?