The code for the problem with addition in js is as follows

<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <title></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <link rel="stylesheet" type="text/css" href="" />
    <!--<script type="text/javascript" src="JS"></script>-->
    <script type="text/javascript">
        function count(){

            //
            //
            //
            //
            //
            var a = document.getElementById("txt1").value;

            var b = document.getElementById("txt2").value;

            var c = document.getElementById("select").value;

            var d = "";

            switch(c)
            {
                case "+":
                d = a + b;
                break;

                case "-":
                d= a - b;
                break;

                case "*":
                d = a * b;
                break;

                case "/":
                d = a / b;
                break;
            }
            document.getElementById("fruit").value = d;
        }
    </script>
    </head>

<body>

    <input type="text" id="txt1" />
    <select id="select">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
    </select>
    <input type="text" id="txt2" />
    <input type="button" value="=" onclick="count()" /> <!--  = , -->
    <input type="text" id="fruit" />

</body>
</html>

everything else is normal except addition

Mar.20,2021

var a = Number(document.getElementById("txt1").value);
var b = Number(document.getElementById("txt2").value);

learn about implicit type conversion , and + besides addition , there are connector functions

. < hr >

you can cast a , b , c and so on with Number and you will know what the problem is

.

ha, you are like this. The an and b you get are themselves

. < H1 > string type < / H1 >

then,

in js < H1 > + < / H1 > The other type of

sign is used to concatenate strings.
so, normally, you should do something like this while calculating money

< H1 > a = parseFloat (a) < / H1 > < H1 > b = parseFloat (b) < / H1 > When a

string is added to a string, it is still a string.


is treated as a string and converted to number type

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e49190-44ce5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e49190-44ce5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?