Conversation
| // Implement this with a single condition. | ||
| function isInRange (num, lower, upper) { | ||
|
|
||
| return (lower<=num&&num<=upper); |
There was a problem hiding this comment.
Just a note - the brackets aren't really needed here, but if you find it easier to read like this then that's no problem :)
| // if statement. | ||
| function isHelloOrGoodbye (val1) { | ||
|
|
||
| if (val1 === "Hello" || val1 === "Goodbye") { |
There was a problem hiding this comment.
This could be simplified to
return val1 === 'Hello' || val1 === 'Goodbye'|
|
||
| if (age === 0) { | ||
| return "Baby" | ||
| } else if (1<=age&&age<=4){ |
There was a problem hiding this comment.
This might just be a personal thing for me, but I find it harder to read conditions laid out like 1<=age. I think it's easier to read when you set them out such as age >= 1
There was a problem hiding this comment.
That makes sense, initially I tried 1<=age<=4 but this always seems to evaluate to true?
| // This function should return true if there are no elements in the array, false otherwise | ||
| function isArrayEmpty (array) { | ||
|
|
||
| return array.length === 0 ? true : false; |
There was a problem hiding this comment.
You don't need the ternary operator here. You could just use
return array.length === 0| // This function should return true if num1 is greater than num2, false otherwise | ||
| function isGreaterThan (num1, num2) { | ||
|
|
||
| return num1 > num2 == true; |
There was a problem hiding this comment.
You don't need the == true here. num > num2 will create a boolean value. The computer will calculate this like so:
return num1 > num2 == true
return true == true
// or (depending on the values of num1/num2)
return false == trueSo you could simplify it to:
return num1 > num2|
|
||
| let vowelCount=0; | ||
| for (i=0; i<val1.length; i++) { | ||
| if (val1.charAt(i).toLowerCase() === 'a'|| |
There was a problem hiding this comment.
This works well! Alternative way of doing this could be to have an array containing the vowels, and check if the current letter is inside that array. The advantage of this is that it's a little more readable. For example:
const vowels = ['a', 'e', 'i', 'o', 'u']
for(let i = 0; i < val1.length; i++) {
if(vowels.includes(val1.charAt(i)) {
vowelCount++
}
}| let sliceValue = val1.length/2; | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| return (val1.length%2===1) ? |
There was a problem hiding this comment.
This is a great use of the ternary operator!
| // Winter - December to February | ||
| function seasonForMonth (monthName) { | ||
|
|
||
| if (monthName==="March"||monthName==="April"||monthName==="May"){ |
There was a problem hiding this comment.
This works well! As I mentioned above, it might be a little bit more readable if you used arrays containing the seasons and to check them like that. Both are good implementations though!
|
|
||
| // Set this variable to firstName and secondName concatenated | ||
| const fullName = null | ||
| const fullName = `${firstName} ${secondName}` |
There was a problem hiding this comment.
Great use of the JS string interpolation!
No description provided.