Prompt the user to enter 2 values in turn through the prompt box, and pop up the maximum value entered by the user after the user input is completed;

Prompt the user to enter 2 values ​​in turn through the prompt box, and pop up the maximum value entered by the user after the user input is completed;

<!DOCTYPE html>

 

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>

</head>

<body>

    <script>

        var num1 = Number ( prompt ( ' Please enter the first number ' ));

        // 2. Declare the second variable and input the data

        var num2 = Number ( prompt ( ' Please enter the second number ' ));

        // 3. Determine who is older and who is younger

        if (num1 > num2) {

            // If true, output the second number

            console.log ( ' The maximum value is : ' + num1 ) ;

        } else {

            // If false, output the first number

            console.log ( ' The maximum value is : ' + num2 ) ;

        }

    </script>

</body>

</html>

 

 var num=Number(prompt('Please enter a number')): Use Number() to convert the data type. Because the data entered by the prompt is a string type by default, if you want to change it into a number type, you need to convert the data type; if you don’t know what data type to convert to, use Number().

parseInt() is converted to an integer type

parseFloat() is converted to a floating point number

Number() is converted to a numeric type.

Guess you like

Origin blog.csdn.net/qq_48491815/article/details/125666082