220 lines
4.5 KiB
Markdown
220 lines
4.5 KiB
Markdown
# 运算符相关
|
||
1. 两个自定义变量进行相等对比,弹出运算结果。 (分别放两个按钮 第一个弹出==的比较结果 第二个弹出 ===的比较结果)
|
||
2. 完成计算器的功能 输入两个数 输出计算结果 具体计算功能包含 加减乘除成方取余 每个计算方式分别放按钮 点击输出计算结果
|
||
3. 用js 取模实现表格的隔行换色
|
||
4. 求商取模应用于秒转时间 输入框单位为秒
|
||
思路:不管输入框获取到的数字是多少,都执行除60取分钟,除600取小时,最后取模为秒数。通过parseInt取整数
|
||
5. 判断是否为两位数
|
||
6. 写出运算符优先级
|
||
7. 计算年龄案例:输入生日输出年龄 并且判断是否能进入网吧
|
||
8. 运算符的优先级
|
||
9. 下面代码的执行结果为
|
||
```
|
||
var age = 29;
|
||
var anotherAge = --age + 2;
|
||
alert(age);
|
||
alert(anotherAge);
|
||
|
||
var time=1
|
||
var newtime=time++
|
||
console.log(time,newtime)
|
||
|
||
```
|
||
|
||
11. 下面代码的执行结果为
|
||
```
|
||
<script>
|
||
var a =1;
|
||
function test(){
|
||
alert(a);
|
||
var a = 2;
|
||
alert(a);
|
||
}
|
||
test();
|
||
alert(a);
|
||
</script>
|
||
|
||
```
|
||
12. 下面代码的执行结果为
|
||
```
|
||
var x = 7;
|
||
x += 8;
|
||
console.log(x)
|
||
|
||
|
||
var y=7
|
||
y=+8;
|
||
console.log(y)
|
||
|
||
```
|
||
|
||
13. 下面代码的执行结果为:
|
||
```
|
||
txt1 = "Hello ";
|
||
txt1 += "Kitty!";
|
||
console.log(txt1)
|
||
|
||
console.log(x = 7 + 8;)
|
||
console.log(y = "7" + 8;)
|
||
console.log(z = "Hello" + 7;)
|
||
|
||
```
|
||
|
||
14. 已知 x=5 分别写出下列语句的打印结果
|
||
x == 8
|
||
x == 5
|
||
x == "5"
|
||
x === 5
|
||
x === "5"
|
||
x != 8
|
||
x !== 5
|
||
x !== "5"
|
||
x !== 8
|
||
x > 8
|
||
x < 8
|
||
x >= 8
|
||
x <= 8
|
||
|
||
|
||
15. 已知 x=6 y=3 分别写出下列语句的打印结果
|
||
x < 10 && y > 1
|
||
x == 5 || y == 5
|
||
!(x == y)
|
||
|
||
|
||
16. 已知现有fish="23"
|
||
var cat = (fish < 18) ? "再来一筐锦鲤":"吃饱啦";
|
||
最后的cat 打印结果为
|
||
|
||
17. 写出下面的打印结果
|
||
2 < 12
|
||
2 < "12"
|
||
2 < "John"
|
||
2 > "John"
|
||
2 == "John"
|
||
"2" < "12"
|
||
"2" > "12"
|
||
"2" == "12"
|
||
|
||
18. 写出下面的打印结果
|
||
```
|
||
txt1="What a very ";
|
||
txt2="nice day";
|
||
txt3=txt1+txt2;
|
||
console.log(txt3)
|
||
var x = 1;
|
||
x = -x;
|
||
alert( x );
|
||
|
||
var x = 1, y = 3;
|
||
alert( y - x );
|
||
|
||
```
|
||
|
||
19. 写出下面的打印结果
|
||
```
|
||
alert( 5 % 2 );
|
||
alert( 8 % 3 );
|
||
alert( 2 ** 2 );
|
||
alert( 2 ** 3 );
|
||
alert( 2 ** 4 );
|
||
alert( 4 ** (1/2) );
|
||
alert( 8 ** (1/3) );
|
||
alert( '1' + 2 );
|
||
alert( 2 + '1' );
|
||
alert(2 + 2 + '1' );
|
||
var x = 1;
|
||
alert( +x );
|
||
|
||
var y = -2;
|
||
alert( +y );
|
||
|
||
// 转化非数字
|
||
alert( +true );
|
||
alert( +"" );
|
||
|
||
var apples = "2";
|
||
var oranges = "3";
|
||
alert( apples + oranges );
|
||
alert( Number(apples) + Number(oranges) );
|
||
```
|
||
20. 运算符优先级
|
||
21. 下面代码的执行结果为
|
||
```
|
||
let a = 1;
|
||
let b = 2;
|
||
|
||
let c = 3 - (a = b + 1);
|
||
|
||
alert( a );
|
||
alert( c );
|
||
|
||
```
|
||
|
||
```
|
||
let a, b, c;
|
||
|
||
a = b = c = 2 + 2;
|
||
|
||
alert( a );
|
||
alert( b );
|
||
alert( c );
|
||
|
||
let n = 2;
|
||
n += 5;
|
||
n *= 2;
|
||
|
||
alert( n );
|
||
|
||
let n = 2;
|
||
n *= 3 + 5;
|
||
alert( n );
|
||
|
||
```
|
||
|
||
22. 下面代码的打印结果为
|
||
```
|
||
alert( true || true ); // true
|
||
alert( false || true ); // true
|
||
alert( true || false ); // true
|
||
alert( false || false ); // false
|
||
|
||
```
|
||
|
||
```
|
||
alert( 1 || 0 );
|
||
|
||
alert( null || 1 );
|
||
alert( null || 0 || 1 );
|
||
alert( undefined || null || 0 )
|
||
var firstName = "";
|
||
var lastName = "";
|
||
var nickName = "SuperCoder";
|
||
alert( firstName || lastName || nickName || "Anonymous");
|
||
```
|
||
23. 下面代码会执行嘛 为什么
|
||
```
|
||
true || alert("not printed");
|
||
false || alert("printed");
|
||
```
|
||
|
||
24. 下面代码的执行结果
|
||
```
|
||
alert( 1 && 0 );
|
||
alert( 1 && 5 );
|
||
alert( null && 5 );
|
||
alert( 0 && "no matter what" )
|
||
alert( 1 && 2 && null && 3 )
|
||
alert( 1 && 2 && 3 )
|
||
alert( !!"non-empty string" );
|
||
alert( !!null );
|
||
alert( Boolean("non-empty string") );
|
||
alert( Boolean(null) );
|
||
alert( null || 2 || undefined );
|
||
alert( alert(1) || 2 || alert(3) )
|
||
alert( alert(1) && alert(2) );
|
||
alert( null || 2 && 3 || 4 );
|
||
|
||
```
|
||
附加
|
||
游戏开始时,显示12个图像的背面,用鼠标点击其中任意一张,即可显示图像的正面,如果点击了两张,则显示出两张图像的正面。如果点击过的两张图像是相同的图像,则将图像从界面中移除 |