当前位置:网站首页>Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
2022-07-02 12:45:00 【By the Difeng River】
List of articles
again i++ and ++i
let i = 1;
alert(i++ + ++i + i) //7
Comparison operator
Use of comparison operators
alert(5 == "5") //true
alert(5 === "5") //false
alert(5 !== "5") //true
- String comparison , Is the character corresponding to the comparison ASCII code
Compare from left to right
If the first is the same, compare the second , And so on
Relatively few , Understanding can - NaN Not equal to any value , Include It itself
- As far as possible Don't compare decimals , Because there is a precision problem with decimals
- Implicit conversion occurs when comparing different types
Finally, the data is implicitly transformed intonumber
Compare the types again
So in development , If we make an accurate comparison, we prefer === perhaps !==
if sentence
Pay attention to the use of parentheses .
Ternary operator
Judge the maximum value of two numbers
let first = +prompt(" First number :")
let second = +prompt(" The second number :")
alert(first > second ? first : second)
Be careful : there prompt
Ahead +
No. is very necessary , Implicitly convert to Number
type .( Otherwise, enter 5,10 The maximum output result is 5
, the reason being that String comparison )
switch sentence
Be careful :switch
The data in should be consistent with case
The value in is Congruent
while sentence
//while Simple circulation ATM machine
let total = 0; // It's defined in script Global variables in the block level
let money = 0; // It's defined in script Global variables in the block level
while (true) {
let i = +prompt(` Please select your operation : 1. deposit 2. Withdraw money 3. Check the balance 4. sign out `)
if (i === 4) {
break // Jump out of while loop
}
switch (i) {
case 1:
money = +prompt(" Please enter your deposit amount :")
total += money
break // Jump out of switch loop
case 2:
money = +prompt(" Please enter your withdrawal amount :")
total -= money
break // Jump out of switch loop
case 3:
alert(total)
}
}
for Loop statement multiplication table
<style>
div {
display: inline-block;
height: 25px;
line-height: 25px;
margin: 5px;
background-color: pink;
padding: 0 10px;
border: 1px solid hotpink;
color: deeppink;
border-radius: 5px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, .2);
text-align: center;
}
</style>
</head>
<body>
<script>
// Print a few lines on the outer layer
for (let i = 1; i <= 9; i++) {
// Print a few stars on the inner layer
for (let j = 1; j <= i; j++) {
// Just need it * Switch to 1 x 1 = 1
document.write(`<div> ${
j} x ${
i} = ${
j * i} </div>`)
}
document.write('<br>')
}
</script>
</body>
边栏推荐
- Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
- Redis avalanche, penetration, breakdown
- H5 to app
- 线性DP AcWing 897. 最长公共子序列
- FBX import under ue4/ue5 runtime
- LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
- 2.6 using recursion and stack - [tower of Hanoi problem]
- Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
- 哈希表 AcWing 840. 模拟散列表
- Input box assembly of the shutter package
猜你喜欢
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
通过反射执行任意类的任意方法
堆 AcWing 839. 模拟堆
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
Dijkstra AcWing 850. Dijkstra求最短路 II
Hash table acwing 841 String hash
8 examples of using date commands
Counting class DP acwing 900 Integer partition
Linear DP acwing 902 Shortest editing distance
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
随机推荐
BOM DOM
ArrayList与LinkedList效率的对比
High performance erasure code coding
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
Wechat official account payment prompt MCH_ ID parameter format error
Linear DP acwing 896 Longest ascending subsequence II
Do you know all the interface test interview questions?
Distributed machine learning framework and high-dimensional real-time recommendation system
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Linear DP acwing 895 Longest ascending subsequence
Use sqoop to export ads layer data to MySQL
. Net, C # basic knowledge
"As a junior college student, I found out how difficult it is to counter attack after graduation."
Embedded Software Engineer career planning
线性DP AcWing 902. 最短编辑距离
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
JDBC 预防sql注入问题与解决方法[PreparedStatement]
Hash table acwing 840 Simulated hash table
bellman-ford AcWing 853. 有边数限制的最短路
哈希表 AcWing 841. 字符串哈希