Skip to content

JavaScript fundamentals#23

Open
7LGnGZkY wants to merge 25 commits intoboolean-uk:mainfrom
7LGnGZkY:main
Open

JavaScript fundamentals#23
7LGnGZkY wants to merge 25 commits intoboolean-uk:mainfrom
7LGnGZkY:main

Conversation

@7LGnGZkY
Copy link

No description provided.


// TODO: write code in this function body to pass the tests

return num >= lower && num <= upper ? 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.

This ternary operator isn't required. num >= lower && num <= upper will return either true or false (depending on the values of num, lower, and upper). Therefore you can just return that boolean value:

return num >= lower && num <= upper


// TODO: write code in this function body to pass the tests

return val1 == 'Hello' || val1 == 'Goodbye' ? 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.

Same as above - return val1 == 'Hello' || var1 == 'Goodbye' will create a boolean value. Therefore we can just return that value.

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


// TODO: write code in this function body to pass the tests
return age === 0 ? 'Baby' :
age >= 1 && age <= 4 ? 'Toddler' :
Copy link
Contributor

Choose a reason for hiding this comment

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

Nested ternaries are not a good idea to use generally. They're not easy to read, and harder to maintain than if/else statements. It's especially hard if you wanted to add a new case to match; for example if you wanted to add a new age description such as "Young adult"


// TODO: write code in this function body to pass the tests

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.

As I've mentioned above, this can be simplified to

return array.length == 0


// TODO: write code in this function body to pass the tests

if (num1 > num2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

num1 > num2 creates a boolean value. So like above with the comments about ternary statements; you can just return this value.

return num1 > num2

function isHello(val1) {
// TODO: write code in this function body to pass the tests

if (val1 == 'Hello') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, you don't need the if statement here, you can just return val1 == 'Hello'

// TODO: Update the code below so that the tests pass

const numOnePlusNumTwo = 0 // Set this variable to numOne plus numTwo
const numOnePlusNumTwo = 12 // Set this variable to numOne plus numTwo
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be achieving using numOne + numTwo. However based off the rest of your submission I feel you understand how you can add two variables together :)

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