Skip to content

omar submission#10

Open
alsyoufomar wants to merge 2 commits intoboolean-uk:mainfrom
alsyoufomar:main
Open

omar submission#10
alsyoufomar wants to merge 2 commits intoboolean-uk:mainfrom
alsyoufomar:main

Conversation

@alsyoufomar
Copy link

No description provided.

function getResult(didPass) {
if (didPass == true) {
return "Well done, you passed!";
} else {
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 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;
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. The ternary operator is not needed. This can be simplified to

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


function getAgeDescription(age) {
return age === 0
? "Baby"
Copy link
Contributor

Choose a reason for hiding this comment

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

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;
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 to:

return array.length == 0

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.

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

This if statement is not needed :)

count++;
}
}
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.

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";
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 incorrect. You need to get the "Delhi" and the "London" values via the cities array.

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