Logical statements without if in functions in JavaScript
Let's say we have a function with an if. Here it is:
javascriptfunction func(a, b) {
if (a > b) {
return true;
} else {
return false;
}
}
As you already know from the previous lessons,
the if constructs that return Boolean
values can be rewritten in a shortened form.
Let's do that:
javascriptfunction func(a, b) {
return a > b;
}
Задание 1
Given the following function:
javascriptfunction func(a, b) {
if (a == b) {
return true;
} else {
return false;
}
}
Rewrite its code in an shortened form according to the theory studied.
Задание 2
Given the following function:
javascriptfunction func(a, b) {
if (a != b) {
return true;
} else {
return false;
}
}
Rewrite its code in an shortened form according to the theory studied.
Задание 3
Given the following function:
javascriptfunction func(a, b) {
if (a + b >= 10) {
return true;
} else {
return false;
}
}
Rewrite its code in an shortened form according to the theory studied.
Задание 4
Given the following function:
javascriptfunction func(num) {
if (num >= 0) {
return true;
} else {
return false;
}
}
Rewrite its code in an shortened form according to the theory studied.