• JS学习记录(es补充一)


    国际通用命名规则
    <html lang="en"> <head> <meta charset="UTF-8"> <title>命名规则</title> </head> <body> <!--国际通用的命名规则:驼峰法则 <一:变量> 1:单个单词的全小写 var name = "lzw"; 2:多个单词 第一个单词全小写,其余单词首字母大写 var myName = "lzw"; var showHelloWord = "HelloWord"; <二:类> 3:全部单词的首字母都要大写 PersonName <三:常量> 4:所有单词的字母全大写 COUNTRYNAME --> <!--类和常量与Java相关--> </body> <script> var name = "lzw"; var myName = "lzw"; </script> </html>
    Number函数
    <html lang="en"> <head> <meta charset="UTF-8"> <title>Number函数</title> </head> <body> <script> var b = "1"; var i = 1; alert(b === i); /*alert(Number(true));*/ </script> </body> </html>

    结果图:

    Typeof类型
    <html lang="en"> <head> <meta charset="UTF-8"> <title>Typeof</title> </head> <body> <script> /*undefined*/ var i; // alert(typeof i); /*boolean*/ var b = true; // alert(typeof b); /*string*/ var s = "lzw"; // alert(typeof s); /*number*/ var i = 3; // alert(typeof i); var obj = { name:"lzw", age:"保密" } // alert(typeof obj); function show() { alert("hello"); } alert(typeof show); </script> </body> </html>

    结果图:

    Prompt
    <html lang="en"> <head> <meta charset="UTF-8"> <title>Prompt</title> </head> <body> <script> var name = prompt("请输入用户姓名","张三"); alert(name); </script> </body> </html>

    结果图:

    自增自减
    <html lang="en"> <head> <meta charset="UTF-8"> <title>自增自减</title> </head> <body> <!-- ++自增运算 1:++在运算数的前面:先+1 再运算 2:++在运算数的后面:先运算 再+1 --> <script> /* var i = 2; j = i++; alert(j); alert(i);*/ var i = 2; j = ++i; alert(j); alert(i); </script> </body> </html>

    结果图:

    水仙花数
    <html lang="en"> <head> <meta charset="UTF-8"> <title>水仙花数</title> </head> <body> <script> var num = 153; var n1 = parseInt(num/100); var n2 = parseInt(num/10%10); var n3 = parseInt(num%10); var result = n1*n1*n1+n2*n2*n2+n3*n3*n3; Math.pow(n1,3)+Math.pow(n2,3)+Math.pow(n3,3); if (num == result){ alert("是水仙花数!!")} else{ alert("非水仙花数!!") } </script> </body> </html>

    结果图:

    赋值运算符
    <html lang="en"> <head> <meta charset="UTF-8"> <title>赋值运算符</title> </head> <body> <script> var i = 5; i += 5; // 等效 i +=5; 效率高 alert(i); var i2 = 10; i2 -= 7;// i2 = i2 - 7; var i3 = 6; i3 = i3 * 6; // i3 *= 6; var i4 = 12; i4 = i4 / 3; // i4 /= 3; var i5 = 16; i5 = i5 % 6;// i5 %= 6; </script> </body> </html>

    结果图:

    if-else语句
    <html lang="en"> <head> <meta charset="UTF-8"> <title>if-else</title> </head> <body> <script> var i = parseInt(prompt("输入分数")); if (i >= 90) { alert(""); } else if ( i >= 80) { alert(""); } else if ( i >= 60) { alert(""); } else { alert(""); } </script> </body> </html>

    结果图:

    嵌套if结构

    <html lang="en"> <head> <meta charset="UTF-8"> <title>嵌套if结构</title> </head> <body> <script> var score = parseInt(prompt("考试成绩")); var daily = parseInt(prompt("考勤成绩")); if (score >= 60 && daily >= 75) { alert("毕业"); } else { if (score < 60 && daily < 75) { alert("都不合格"); } else if (score < 60) { alert("考试不合格"); } else if (daily < 75) { alert("考勤不合格"); } } </script> </body> </html>

    结果图:

    switch-case语句

    <html lang="en"> <head> <meta charset="UTF-8"> <title>switch-case</title> </head> <body> <script> var month = parseInt(prompt("请输入月份")); switch (month){ case 1: alert("第一季度"); break; case 2: alert("第一季度"); break; case 3: alert("第一季度"); break; case 4: alert("第二季度"); break; case 5: alert("第二季度"); break; case 6: alert("第二季度"); break; case 7: alert("第三季度"); break; case 8: alert("第三季度"); break; case 9: alert("第三季度"); break; case 10: alert("第四季度"); break; case 11: alert("第四季度"); break; case 12: alert("第四季度"); break; default: alert("输入的月份有误"); break; } </script> </body> </html>

    结果图:

  • 相关阅读:
    【习题 6-10 UVA
    【习题 6-9 UVA
    【习题 6-8 UVA
    【NOIP2016练习】T1 挖金矿(二分答案)
    O(n)求1-n的逆元
    【NOIP2016练习】T1 string (计数)
    【NOIP2016练习】T2 跑跑步 (数论)
    【NOIP2016练习】T3 tree (树形DP)
    【CF679B】Theseus and labyrinth(数学,贪心)
    【NOIP2016练习】T2 旅行(树形DP,换根)
  • 原文地址:https://www.cnblogs.com/lizuowei/p/7271641.html
Copyright © 2020-2023  润新知