GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing javascript.info — Sum numbers from the visitor

  • Tutorial
  • The JavaScript language
  • Data types
  • Numbers
back to the lesson

Sum numbers from the visitor

importance: 5

Create a script that prompts the visitor to enter two numbers and then shows their sum.

Run the demo

P.S. There is a gotcha with types.

let a = +prompt("The first number?", "");
let b = +prompt("The second number?", "");

alert( a + b );

Note the unary plus + before prompt. It immediately converts the value to a number.

Otherwise, a and b would be string their sum would be their concatenation, that is: "1" + "2" = "12".

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.