Blogger Information
Blog 34
fans 0
comment 0
visits 20531
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS常用函数及分支与循环
小庄
Original
493 people have browsed it

JS 常用函数及分支与循环

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. let sum = 60;
  12. if(sum < 0 && sum > 100){
  13. console.log("成绩不能小于0或大于100")
  14. }else if(sum >= 60 && sum <= 79){
  15. console.log("良好");
  16. }else if(sum >= 80 && sum <= 89){
  17. console.log("中等");
  18. }else if(sum >= 90 && sum <= 100){
  19. console.log("优秀");
  20. }else if(sum < 60){
  21. console.log("不及格");
  22. }
  23. let count = 1
  24. while(count <= 10){
  25. console.log("循环");
  26. count ++;
  27. }
  28. let arr = ['a','b','c','d','e','f','g'];
  29. for(let i = 0;i < arr.length; i ++){
  30. console.log(arr[i]);
  31. }
  32. console.log("数组长度:"+arr.length); //返回数组长度
  33. console.log("查找数组中字符首次出现的位置:"+arr.indexOf('g')); //查找数组中 g 首次出现的位置
  34. console.log("提取部分字符含头不含尾:"+arr.slice(1,4)); //提取部分字符(截取结果,包含起始位置,不包含终止位置)
  35. console.log("提取部分字符包含头尾:"+'asdfqwer'.substr(1,4)); //提取部分字符(截取结果,包含起始位置与终止位置)
  36. console.log("替换字符:"+'asdfqwer'.replace('qw','替换')); //替换字符
  37. console.log("大小写转换:"+'asdfqwer'.toUpperCase()); //转换为大写 (toLowerCase() 转换为小写; trim()去除空格,等等常用方法可查询js API)
  38. </script>
  39. </body>
  40. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!