We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Truthy and Falsy

A "truthy" value is a value that is considered true when encountered in a Boolean context. In JavaScript, you don't need to explicitly convert a value to a Boolean before using it in a conditional:

if ("hello") {
  console.log("hello is truthy");
}
if (42) {
  console.log("42 is truthy");
}
// hello is truthy
// 42 is truthy

A "falsy" value works the same way, but for values that evaluate to false:

if (!0) {
  console.log("0 is falsy");
}
if (!null) {
  console.log("null is falsy");
}
if (!undefined) {
  console.log("undefined is falsy");
}

Common truthy values include:

  • true
  • 42 (any number that isn't 0)
  • "hello" (any non-empty string)
  • [] (an empty array)
  • {} (an empty object)
  • function() {} (an empty function)

Common falsy values include:

  • false
  • 0
  • "" (an empty string)
  • null
  • undefined
  • NaN (Not a Number)

Assignment

There's an issue with how Textio checks the number of user credits before sending a message, some users that have negative credits are still able to send messages. A user is expected to have at least one credit to be able to send a message.

Fix the bug on line 5 to correctly check whether the user has enough credits.