freeCodeCamp/curriculum/challenges/english/02-javascript-algorithms-an.../basic-algorithm-scripting/boo-who.english.md

2.6 KiB

id title isRequired challengeType
a77dbc43c33f39daa4429b4f Boo who true 5

Description

Check if a value is classified as a boolean primitive. Return true or false. Boolean primitives are true and false. Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

Instructions

Tests

tests:
  - text: <code>booWho(true)</code> should return true.
    testString: assert.strictEqual(booWho(true), true, '<code>booWho(true)</code> should return true.');
  - text: <code>booWho(false)</code> should return true.
    testString: assert.strictEqual(booWho(false), true, '<code>booWho(false)</code> should return true.');
  - text: <code>booWho([1, 2, 3])</code> should return false.
    testString: assert.strictEqual(booWho([1, 2, 3]), false, '<code>booWho([1, 2, 3])</code> should return false.');
  - text: <code>booWho([].slice)</code> should return false.
    testString: assert.strictEqual(booWho([].slice), false, '<code>booWho([].slice)</code> should return false.');
  - text: '<code>booWho({ "a": 1 })</code> should return false.'
    testString: 'assert.strictEqual(booWho({ "a": 1 }), false, ''<code>booWho({ "a": 1 })</code> should return false.'');'
  - text: <code>booWho(1)</code> should return false.
    testString: assert.strictEqual(booWho(1), false, '<code>booWho(1)</code> should return false.');
  - text: <code>booWho(NaN)</code> should return false.
    testString: assert.strictEqual(booWho(NaN), false, '<code>booWho(NaN)</code> should return false.');
  - text: <code>booWho("a")</code> should return false.
    testString: assert.strictEqual(booWho("a"), false, '<code>booWho("a")</code> should return false.');
  - text: <code>booWho("true")</code> should return false.
    testString: assert.strictEqual(booWho("true"), false, '<code>booWho("true")</code> should return false.');
  - text: <code>booWho("false")</code> should return false.
    testString: assert.strictEqual(booWho("false"), false, '<code>booWho("false")</code> should return false.');

Challenge Seed

function booWho(bool) {
  // What is the new fad diet for ghost developers? The Boolean.
  return bool;
}

booWho(null);

Solution

function booWho(bool) {
  return typeof bool === "boolean";
}

booWho(null);