Command Palette

Search for a command to run...

Hectal
Phase 12: AI That Runs in the Browser
AI Frontend · Exercise 1 of 5Next
Intermediate

Pick the Back End

Five pretend devices are listed. Each button picks one and shows the back end your code chooses in #backend. Finish pickBackend(env) so it returns "webgpu", "wasm" or "server".

WebGPU needs env.gpu and an adapter from await env.gpu.requestAdapter(); that call can return null or throw. Use WebAssembly when env.wasm is true. Otherwise use the server.

What Check tests

  1. A desktop with a GPU adapter gets webgpu
  2. A device whose adapter is null gets wasm
  3. A device whose GPU call throws gets wasm, not an error
  4. A device with no WebGPU gets wasm
  5. A device with nothing gets server

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.