Skip to content

Paul JS Fundamentals#15

Open
therearedoors wants to merge 8 commits intoboolean-uk:mainfrom
therearedoors:main
Open

Paul JS Fundamentals#15
therearedoors wants to merge 8 commits intoboolean-uk:mainfrom
therearedoors:main

Conversation

@therearedoors
Copy link

No description provided.

// Implement this with a single condition.
function isInRange (num, lower, upper) {

return (lower<=num&&num<=upper);
Copy link
Contributor

Choose a reason for hiding this comment

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

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") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be simplified to

return val1 === 'Hello' || val1 === 'Goodbye'


if (age === 0) {
return "Baby"
} else if (1<=age&&age<=4){
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

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 == true

So you could simplify it to:

return num1 > num2


let vowelCount=0;
for (i=0; i<val1.length; i++) {
if (val1.charAt(i).toLowerCase() === 'a'||
Copy link
Contributor

Choose a reason for hiding this comment

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

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) ?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great use of the ternary operator!

// Winter - December to February
function seasonForMonth (monthName) {

if (monthName==="March"||monthName==="April"||monthName==="May"){
Copy link
Contributor

Choose a reason for hiding this comment

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

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}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Great use of the JS string interpolation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants