Skip to content

Daniel JS Fundamentals#13

Open
dan1212111 wants to merge 6 commits intoboolean-uk:mainfrom
dan1212111:main
Open

Daniel JS Fundamentals#13
dan1212111 wants to merge 6 commits intoboolean-uk:mainfrom
dan1212111:main

Conversation

@dan1212111
Copy link

No description provided.

function isInRange(num, lower, upper) {
// TODO: write code in this function body to pass the tests

if (num >= lower && 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.

This can be simplified. num >= lower && num <= upper creates a boolean value that represents if num is greater than or equal to lower AND is less than or equal to upper. So we can just return that value instead of doing the if statement. Like so:

return num >= lower && num <= upper

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

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 can also be simplified:

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

// TODO: write code in this function body to pass the tests
const arrayCheck = [];

if (array.length == arrayCheck) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be careful doing this. It does work, but in a little bit of a hacky way. If you wanted to compare the array to an empty array, you could do this like so:

if (array === arrayCheck)

However, by checking the length (which will be 0) against the array, you're actually doing something like this:

if (0 === [])

Javascript will let you do this, but a lot of languages won't. So just be careful!

function isGreaterThan(num1, num2) {
// 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.

This can also be simplified, same as above :)

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

m = Math.min(...nums); {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just return Math.min(...nums) here

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.

This can also be simplified

if (val1 === "Hello") {
return true;
}
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.

If you did simplify the above, you wouldn't need this if statement.

function isNotHello(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 can simplify this by returning val1 !== 'Hello'. Then you wouldn't need the second if statement.

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

if (val1.length > val2.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You could simplify this function by just returning this condition. You wouldn't need the other if statements then:

return val1.length > val2.length

}
}
return count % 2 !== 0
// if (count % 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.

It's always a good remove commented code that isn't needed anymore

function seasonForMonth(monthName) {
// TODO: write code in this function body to pass the tests
Spring= ['March','April','May']
Summer= ['June','July','August']
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 arrays. Just be aware that you should create your variables like so:

const Spring = ['Match', 'April', 'May']

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