Freecodecamp: "Basic JavaScript: Use Multiple Conditional (Ternary) Operators": Indentation after return keyword fails parser even though it is valid JS

Created on 1 Oct 2018  路  3Comments  路  Source: freeCodeCamp/freeCodeCamp

Describe your problem and - if possible - how to reproduce it

In the "Basic JavaScript: Use Multiple Conditional (Ternary) Operators" challenge, the JS parser does not seem to consider the following valid:

function checkSign(num) {
  return
    num > 0 ? "positive" :
    num < 0 ? "negative" :
    "zero";
}

checkSign(10);

If you change it to this, however, it passes:

function checkSign(num) {
  return num > 0 ? "positive" :
    num < 0 ? "negative" :
    "zero";
}

checkSign(10);

Add a Link to the page with the problem

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-multiple-conditional-ternary-operators

Tell us about your browser and operating system

  • Browser Name: Firefox Beta
  • Browser Version: 63.0b10
  • Operating System: Antergos Linux

If possible, add a screenshot here

image

Most helpful comment

It is not valid. When you put a return on single line by itself, the function will return undefined. Please close this, because it is not a bug. but instead a JavaScript feature. The following would be valid (wrapping with parentheses).

function checkSign(num) {
  return (
    num > 0 ? "positive" :
    num < 0 ? "negative" :
    "zero"
  );
}

All 3 comments

It is not valid. When you put a return on single line by itself, the function will return undefined. Please close this, because it is not a bug. but instead a JavaScript feature. The following would be valid (wrapping with parentheses).

function checkSign(num) {
  return (
    num > 0 ? "positive" :
    num < 0 ? "negative" :
    "zero"
  );
}

Ah, you're right. Thanks. :smile: Closing this issue.

THIS GUY DESERVES A ROUND OF APPLAUSE

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ar5had picture ar5had  路  3Comments

raisedadead picture raisedadead  路  3Comments

bagrounds picture bagrounds  路  3Comments

QuincyLarson picture QuincyLarson  路  3Comments

trashtalka3000 picture trashtalka3000  路  3Comments