How do I output the JSON as a valid string?

  • 0
    The task cannot be completed: In the last-bottom field, write the code of the task (x) function that returns JSON as a valid string (which is the result of applying the JSON.stringify function to the object);
    the original object must have a love property with a javascript string value and a year property with a numeric value 2020 and an arg property with a value x.

    function task (x) {
    let user = {
    love: 'javascript',
    year: 2020,
    arg: x
    }
    console.log (JSON.stringify (user, null, 2))
    }

    function task (x) {
    let user = {
    love: 'javascript',
    year: 2020,
    arg: x
    }
    console.log (JSON.stringify (user))
    }

    I tried these two options, but the task does not count with the wording "The expected result was NOT given". Maybe the professionals will tell you where the error is or it was necessary to use a different line output than mine. Particularly confusing is the word "correct" in the assignment ... thanks in advance for the answer ...
    JavaScript Anonymous, Jan 10, 2020

  • 1 Answers
  • 0
    return

    function task(x) {
    let user = {
    love: 'javascript',
    year: 2020,
    arg: x
    }
    return JSON.stringify(user);
    }




    short entry

    const task = x => JSON.stringify({love: 'javascript',year: 2020,arg: x});
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!