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 it.javascript.info — Sommate i numeri forniti dall'utente

  • Tutorial
  • Il linguaggio JavaScript
  • Tipi di dato
  • Numeri
torna alle lezioni

Sommate i numeri forniti dall'utente

importanza: 5

Create uno script che richiede due numeri all’utente (tramite prompt) e successivamente mostra la somma.

Esegui la demo

P.S. Fate attenzione ai tipi.

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

alert( a + b );

Notate la somma unaria + prima di prompt. Converte immediatamente la stringa in numero.

Altrimenti a e b vengono interpretate come stringhe e la loro somma sarebbe la loro concatenazione, cioè : "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.