const result = 2
function dothis() {
const number = 5
if (number < 0) {
result == 0 ? console.log('error')
return false
}
}
Why is this code giving an "unexpected return" error?
const result = 2
function dothis() {
const number = 5
if (number < 0) {
result == 0 ? console.log('error')
return false
}
}
Why is this code giving an "unexpected return" error?
When using ternary condition you need to use the syntax condition?statement:statement
. Thus, you are missing the third part, the statement
, hence the name implies ternary
(three parts).
var results = [];
function dothis() {
const number = -1;
if (number < 0) {
results.length == 0 ? console.log('error'): console.log('no error');
return false
}
}
dothis();
I found out that your conditional if else shorthand is not completed, Else part is missing there.
function dothis() {
const number = 5
if (number > 0) {
results.length == 0 ? console.log('error') : console.log ('success')
return false
}
}
this will complete your condition. Please let me know if you are trying to do something else.
You're missing :
results.length == 0 ? console.log('error') : console.log('success')