Conversation
| function getResult(didPass) { | ||
| if (didPass == true) { | ||
| return "Well done, you passed!"; | ||
| } else { |
There was a problem hiding this comment.
You don't really need the else here, you could just have the
if (didPass == true) {
return "Well done, you passed!";
}
return "Sorry, try again";This is because didPass will either be true or false. So in the case it is true, your function will stop when you return Well done. In the case it is false, it will skip the if statement and go onto the next line; in the code I showed above, it'll return Sorry.
Hope that makes sense!
| function isHelloOrGoodbye (val1) { | ||
|
|
||
| function isHelloOrGoodbye(val1) { | ||
| return val1 === "Hello" || val1 === "Goodbye" ? true : false; |
There was a problem hiding this comment.
Same as above. The ternary operator is not needed. This can be simplified to
return val1 === 'Hello' || val1 === 'Goodbye'|
|
||
| function getAgeDescription(age) { | ||
| return age === 0 | ||
| ? "Baby" |
There was a problem hiding this comment.
This would be better as an if statement. Nested ternarys are really hard to read and even harder to maintain.
| function isArrayEmpty (array) { | ||
|
|
||
| function isArrayEmpty(array) { | ||
| return array.length == 0 ? true : false; |
There was a problem hiding this comment.
This can be simplified to:
return array.length == 0| function isGreaterThan(num1, num2) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (num1 > num2) { |
There was a problem hiding this comment.
The if statement is not needed here as num1 > num2 is already a boolean condition, so you can just return that value such as:
return num1 > num2| function isHello (val1) { | ||
|
|
||
| function isHello(val1) { | ||
| if (val1 === "Hello") { |
There was a problem hiding this comment.
val1 === 'Hello' is a boolean statement, so you don't need the if statement here. You could just return
return val1 === "Hello"| function isNotHello (val1) { | ||
|
|
||
| function isNotHello(val1) { | ||
| if (val1 !== "Hello") { |
There was a problem hiding this comment.
Same as above, the if statement here isn't required as val1 !== "Hello" is a boolean statement.
| function isLongerThan (val1, val2) { | ||
|
|
||
| function isLongerThan(val1, val2) { | ||
| if (val1.length > val2.length) { |
There was a problem hiding this comment.
This if statement is not needed :)
| count++; | ||
| } | ||
| } | ||
| if (count % 2 === 1) { |
There was a problem hiding this comment.
This if statement isn't required as count % 2 === 1 is a boolean statement, so you could just return it :)
|
|
||
| // Set fourthCity to the 4th element in the cities array | ||
| const fourthCity = '' | ||
| const fourthCity = "Delhi"; |
There was a problem hiding this comment.
This is incorrect. You need to get the "Delhi" and the "London" values via the cities array.
No description provided.