0

I am wondering how I can call the summarizeUser function and make the canCode part log to the console as false? Thank you in advance.

var name = 'Maya';
var age = 24;
var canCode = true;

function summarizeUser(userName, userAge, userHasHobby){
    return(
        `Name is ${name}, age is ${age}, can code = ${canCode}`
    );
}

console.log(summarizeUser('Maya', 24, canCode));
  • return false, do not return a string – jsotola Oct 21 '20 at 20:55
  • You should use the argument name in the function. In this case userName instead of name, userAge instead of age and userHasHobby instead of canCode. If you use variables names, your function uses those variables whatever value you passed as arguments. If you need to change canCode value, before return add canCode = false; – Bulent Oct 21 '20 at 20:56
  • Does this answer your question? [Return multiple values in JavaScript?](https://stackoverflow.com/questions/2917175/return-multiple-values-in-javascript) – jsotola Oct 21 '20 at 20:58

3 Answers3

0

var name = 'Maya';
var age = 24;
var canCode = true;

function summarizeUser(userName, userAge, userHasHobby){
   canCode=false;
   console.log( `Name is ${name}, age is ${age}, can code = ${canCode}`);
}
summarizeUser(name,age,canCode);
console.log(canCode);
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
0

I'm not really sure that I understood what you want to do. If I understood it right, then your code does not make sense ;-)

var name = 'Maya';
var age = 24;
var canCode = true;

function summarizeUser(userName, userAge, userHasHobby){
   console.log( 'Name is ' + userName + ', age is ' + userAge + ', canCode = ' + userHasHobby);

   // if you want to write false if user has a hobby, then you can do the following:
   console.log( 'Name is ' + userName + ', age is ' + userAge + ', canCode = ' + !userHasHobby);
}

summarizeUser(name,age,canCode);
Hias
  • 57
  • 3
0

Easy, set canCode=false in the function and log it out.

Island Nic
  • 27
  • 4