Command Palette

Search for a command to run...

Hectal
Phase 11: Network and Browser APIs
JavaScript · Exercise 2 of 5 PreviousNext
Beginner

Build and read search URLs

Write buildSearchUrl(term, page) that returns the full URL https://shop.example.com/search with q set to the term and page set to the page number. Any text must work, even R&D #1.

Write readPage(urlText) that returns the page parameter as a number, or 1 when it's missing or not a positive whole number.

What Check tests

  1. buildSearchUrl("red shoes", 2) points to /search with q and page
  2. Special characters survive: R&D #1
  3. readPage reads page=4 as the number 4
  4. readPage returns 1 when page is missing
  5. readPage returns 1 for page=abc or page=-2

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.