Blogger Information
Blog 36
fans 1
comment 0
visits 26433
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js数据类型、分支、循环
早晨
Original
432 people have browsed it

运行效果

JS代码

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>js数据类型、分支、循环</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 数据类型
  12. let a='OK';
  13. console.log(typeof a);
  14. console.log('--------------------------');
  15. let b=100;
  16. console.log(typeof b);
  17. console.log('--------------------------');
  18. let c=['姓名','年龄','学历'];
  19. console.log(typeof c);
  20. console.log('--------------------------');
  21. let d;
  22. console.log(d);
  23. // 分支
  24. let age = 60;
  25. if(age >=60){
  26. console.log('老年人');
  27. }
  28. console.log('-------------------------');
  29. let ages = 35;
  30. if(ages >=50){
  31. console.log('中年人');
  32. }else{
  33. console.log('青年人');
  34. }
  35. console.log('-------------------------');
  36. let fs=75;
  37. if(fs >=90 && fs<120){
  38. console.log('你的分数为:A+');
  39. }
  40. else if(fs >70 && fs<80){
  41. console.log('你的分数为:A');
  42. }
  43. else if(fs >60 && fs<70){
  44. console.log('你的分数为:B+');
  45. }else{
  46. console.log('你的分数为:B');
  47. }
  48. const colors =['red','green','blue'];
  49. console.log(colors);
  50. console.log('-------------------------------------------');
  51. // for循环方式
  52. for(let i=0; i<colors.length; i++){
  53. console.log(colors[i]);
  54. }
  55. console.log('-------------------------------------------');
  56. // for-in循环方式
  57. for(let item in colors){
  58. console.log(item+':'+colors[item]);
  59. }
  60. console.log('-------------------------------------------');
  61. // for-of 循环方式
  62. for(let item of colors.values()){
  63. console.log('颜色:'+ item);
  64. }
  65. console.log('-------------------------------------------');
  66. for(let item of colors.keys()){
  67. console.log('键值:'+ item);
  68. }
  69. console.log('-------------------------------------------');
  70. for(let item of colors.entries()){
  71. console.log('键值+颜色:' + item);
  72. }
  73. </script>
  74. </body>
  75. </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