Command Palette

Search for a command to run...

Hectal
Phase 11: Files, Images and Voice
AI Frontend · Exercise 1 of 5Next
Beginner

Check a File Before You Accept It

A file picker lists the files a person chooses. Write validate(file) so it returns a sentence when the file must be refused, and null when it is fine. The page already shows the accepted names in #list and the sentences in #error.

Refuse, in this order: an empty file (<name> is empty.), a file bigger than 1 MB (<name> is too big.), and any type other than image/png or image/jpeg (<name> is not a PNG or JPEG.). Use the file's name, size and type.

What Check tests

  1. A normal PNG is listed and no error shows
  2. An empty file is refused with <name> is empty.
  3. A file over 1 MB is refused with <name> is too big.
  4. A GIF is refused with <name> is not a PNG or JPEG.
  5. A good and a bad file together: the good one is still listed

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.