Course outline
Full-Stack course / JavaScript fundamentals

Describe the box

Lab

How to fetch and submit this exercise

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each exercise: download it, edit the file named in the instructions, then submit.

gonomicon fetch fs-week-2/01-02-describe-the-box
cd 01-02-describe-the-box
gonomicon submit

The runner depends on the exercise: JavaScript/TypeScript/React labs run with Vitest, Python labs with pytest, and config-file labs (Docker, CI, Terraform, Nginx) are checked by parsing your file. gonomicon test runs the visible checks on your computer first; submitting also runs the hidden checks on our server.

Describe the box

Goal: look at the value in a box and say, in plain words, what kind of thing it is.

Worked example

The file starts with a box called value. The tests swap in different values, run your code, and read the kind box you filled in.

What value holdskind should end up as
42"number"
"42""text"
false"yes/no"
undefined (a box made with let value; and never packed)"empty"
null"nothing"
NaN (what you get from Number("abc"))"not a number"

Notice that 42 and "42" look alike but get different answers, and that undefined and null do too.

Rules

  • Keep the line let value = ...; at the top of the file. The tests replace it with other values.
  • Your code goes below it and must leave one of the six exact words above in kind. Use an if, else if, else chain or a switch to choose.
  • Compare with ===, not ==.
  • Don't use var.
  • To look at your result while you work, add console.log(kind); at the bottom and run node describe_the_box.js.

What you'll practice

  • Telling the shapes of values apart, including the odd ones
  • Why strict equality matters
  • Choosing between tracks in the right order

Run it

gonomicon fetch fs-week-2/01-02-describe-the-box
cd 01-02-describe-the-box
gonomicon test
gonomicon submit

Hints

  1. Add console.log(typeof value); and try several different values. Which shapes give you a word you can use as it is, and which give you something you don't want?
  2. Two values are tricky: NaN reports itself as a number, and null does not report itself as "null". Check for those special values first, before you ask about the shape.
  3. Check value === null first, then value === undefined, then Number.isNaN(value). After that, typeof value tells you number, string or boolean, and each one maps to a word in the list.