<Js>运算

//delete使用
    //补码
    //位运算not~、and&、or、xor
    //var nv = new Number(20)
    //var nV = ~nv//或nV = -nv-1
    //document.write(nV+"<br>")
    //and运算规则:1&1=1,1&0=0,0&1=0,0&0=0
    //or运算规则:1|1=1,1|0=1,0|1=1,0|0=0
    //xor运算规则:1^1=0,1^0=1,0^1=1,0^0=0
    //左移<< 右移>> 无符号右移动>>>

    //乘法 Infinity(太大)-Infinity(太小)
        //Infinity/Infinity=NaN
        //除0外,Infinity乘以任何数字为Infinity或-Infinity
        //0除一个任何非无穷大的数字,结果为 NaN
    //-Infinity+Infinity=NaN
        var bFound = false;
var i = 0;

while (!bFound) {
  if (aValue[i] == vSearchValues) {
    bFound = true;
  } else {
    i++;
  }
}
    //关系运算,在比较中,首先应将两个变量或公式转换成统一的类型,
        //之后再次比较,返回的结果为boolean
    //等性运算
        //null和 undefined 无法转换成其他val
        /*  特殊情况:
            false == 0      true
            true == 1       true
            NaN!=NaN        true
            null==undefined true
            "5" == 5        true
            "NaN" == NaN   false
            5 == NaN       false
            NaN == NaN     false
            true == 2      false
            undefined == 0 false
            null == 0      false
        */
    //条件运算:var iv = (val_1 > val_2) ? val_1 : val_2
    //赋值运算: *= /= %= += -= <<= >>= >>>=
    //逗号运算 var a,b,c
    //逻辑运算:
        /*Undefined     false
        Null    false
        Boolean     结果等于输入的参数(不转换)
        Number  如果参数为 +0, -0 或 NaN,则结果为 false;否则为 true。
        String  如果参数为空字符串,则结果为 false;否则为 true。
        Object  true*/
        //只有在&前后都为true时,才会返回true.
        //只有在|前后都为false时,才会返回false.
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <style> body { display: flex; flex-direction: column; align-items: center; font-family: Arial, sans-serif; } .calculator { border: 2px solid #ccc; padding: 20px; border-radius: 8px; background-color: #f9f9f9; } input { width: 60px; padding: 6px; margin: 4px; text-align: center; } select { padding: 6px; margin: 4px; } button { background-color: #4CAF50; color: white; padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; margin-top: 10px; } #result { font-size: 24px; margin-top: 10px; color: #333; } </style> </head> <body> <h2>开始计算</h2> <div class="calculator"> <input type="number" id="num1" value="2"> <select id="operator"> <option value="+">+</option> <option value="-">-</option> <option value="*">×</option> <option value="/">÷</option> </select> <input type="number" id="num2" value="1"> <br> <button onclick="calculate()">=</button> <div id="result">3</div> </div> <script> function calculate() { const num1 = parseFloat(document.getElementById('num1').value); const num2 = parseFloat(document.getElementById('num2').value); const operator = document.getElementById('operator').value; let result; switch(operator) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': result = num1 / num2; break; default: result = '错误'; } document.getElementById('result').textContent = result; } </script> </body> </html>
最新发布
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值