How to log with return statement


#1


https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/2/3?curriculum_id=506324b3a7dffd00020bf661


Hey guys just wanted to know how I would log my code to the console using a return statement. Specifically the "return true" part of my function. Anyone have any ideas in mind?


 
var tired = true;
var bored = false;

function nap() {
  if (tired || bored) {
      return true;
  } else {
      return false;
  }
  
};


#2

Hey.

You could simply place your function call inside your console.log parentheses. i.e.

console.log( "Take a nap? " + nap() ); //Prints "Take a nap? true/false"

Or you could first assign the return result to a new variable then place that variable in your console.log statement. i.e.

var result = nap();

console.log( "Take a nap? " + result ); //Will also print "Take a nap? true/false"

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.