Blogger Information
Blog 33
fans 0
comment 0
visits 19802
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月16号作业-javascript--php培训九期线上班
取个名字真难
Original
537 people have browsed it

javascript变量、函数的定义

javascript流程控制if else switch

javascript三种循环

数据类型转换:parseInt、isNaN函数的使用

  1. <div>
  2. <input type="text" id="intext" value="" name="intext" placeholder="输入年纪">
  3. <button onclick="test4()">提交</button>
  4. </div>
  5. <script >
  6. // 数据类型转换:parseInt、isNaN函数的使用
  7. function test4() {
  8. var text1=document.getElementById('intext').value;
  9. text1=parseInt(text1);
  10. if (!isNaN(text1)){
  11. if (text1>18&&text1<=100) {
  12. alert('你输入的年纪是:'+text1);
  13. }else {
  14. alert('你输入的年纪不正确');
  15. }
  16. }else{
  17. alert("输入数据不正确请重新输入")
  18. }
  19. } // 全局变量的定义
  20. var result=80;
  21. // 函数的定义
  22. function test(){
  23. // 函数内部定义的变量的作用域为局部只在此函数部起作用
  24. var myTest='我的javascript成绩是:';
  25. // if条件语句
  26. if (result>=60 &&(parseInt(result))<70){
  27. console.log(myTest+'一般');
  28. }else if (result>=70&&result<90){
  29. console.log(myTest+'成绩还行');
  30. }else if (result>=90 &&result<=100){
  31. console.log(myTest+'成绩不错');
  32. }else if (result<60){
  33. console.log(myTest+'成绩没有及格');
  34. }
  35. }
  36. // 执行或调用函数
  37. test();
  38. function test2() {
  39. var myTest='我的javascript成绩是用witch语句:';
  40. // switch语句
  41. switch (true) {
  42. case result>=90:
  43. console.log(myTest+'优秀');
  44. break;
  45. case result>=80:
  46. console.log(myTest+'还行吧') ;
  47. break;
  48. case result>= 60:
  49. console.log(myTest+'及格的边缘疯狂试探');
  50. break;
  51. default:
  52. console.log(myTest+'很差了还没及格赶紧学习去');
  53. }
  54. }
  55. // 执行或调用函数
  56. test2();
  57. function test3() {
  58. // 求1到100的和 for循环
  59. var sum=0;
  60. for (var i=1;i<=100; i++)
  61. {
  62. sum+=i;
  63. }
  64. console.log(sum);
  65. // do while 循环
  66. var i=1;
  67. var sum2=0;
  68. do {
  69. sum2=sum2+i;
  70. i++;
  71. }while (i<=100);
  72. console.log(sum2);
  73. var w=1;
  74. var sum3=0;
  75. // while 循环
  76. while (w<=100){
  77. sum3=sum3+w;
  78. w++;
  79. }
  80. console.log(sum3);
  81. }
  82. // 执行或调用函数
  83. test3();
  84. </script>
Correction status:Uncorrected

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