← 返回首页
Sum numbers from the visitor
EN

We want to make this open-source project available for people all around the world.

Help to translate the content of this tutorial to your language!

    Search
    Search
    Light themeDark theme
    عربيDanskEnglishEspañolفارسیFrançaisIndonesiaItaliano日本語한국어РусскийTürkçeУкраїнськаOʻzbek简体中文
    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.

    solution
    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".