Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

London10-Onur-Atas-JavaScript-Core-1-Coursework-Week2 #464

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

onurat
Copy link

@onurat onurat commented May 25, 2023

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 repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

Comment on lines +14 to +16
let isHappy = mood;

if (isHappy) {
if (isHappy === true) {

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?

Comment on lines +24 to +26
let isBigEnough = num;

if (isBigEnough) {
if (isBigEnough > 10) {

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?

Comment on lines +7 to +15
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.

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.

Comment on lines +26 to +37
function applyDiscount(totalPrice) {
if (totalPrice >= 200) {
return totalPrice * 0.9;
}
else {
return totalPrice * 0.95;

/*
}



}

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

Comment on lines +43 to +52
function printOddNumbers(limit) {

for (let i = 0; i <= limit; i++) {
if (i % 2 === 1) {
console.log(i);
}
}


}

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.

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.

Comment on lines +58 to +68
function buyTwoGetTheCheapestFree(price1, price2) {
if (price1 > price2) {
return price1;
}
else {
return price2;

}


}

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.

Comment on lines +93 to +97
function countReverse(number) {
for (let i = number; i >= 1; i--) {
console.log(i);
}
}

Choose a reason for hiding this comment

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

Nice work

Comment on lines +75 to +83
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";
}
}

Choose a reason for hiding this comment

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

Nice work

@JackRogers9
Copy link

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 :

function getMood(isHappy) {
  if (isHappy) {
    return "I am happy";
  } else {
    return "I am not happy";
  }
}

With a ternary operator expression:

function getMood(isHappy) {
  return isHappy ? "I am happy" : "I am not happy";
}

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants