StreetDocsPlayground
StreetDocs/Make Your Web Page Smart/Market Price Calculator (Project)
javascript
20 minLearning in Pidgin

Market Price Calculator (Project)

Build a calculator wey customers fit use to add market prices.

What you'll learn

  • Use variables and functions together
  • Read values from inputs
  • Update the page with innerText

Before you start

  • buttons-and-dom

You don learn variables, numbers, decisions, functions and buttons. Now use all of them to build Ada's market price calculator.

How e go work

  • Two input boxes: one for rice price, one for beans price
  • A button wey say "Calculate total"
  • A paragraph where di total go show

Your plan

Use document.getElementById to read wetin dey inside each input (input.value), convert am to a number with Number(...), add dem, and show di result with innerText. If di button no get event listener, nothing go happen — so remember addEventListener("click", ...).

Test am for di playground: type 850 and 450, press di button, and you go see 1300 for di page. Congratulations — you don build a real, working app!

Project

Market price calculator

Build an interactive calculator that adds two market prices and shows the total on the page.

  • Add two number inputs
  • Add a button wey dey calculate
  • Read di values and add dem with Number()
  • Show di total with innerText