JavaScript基础教程

文章39 |   阅读 23221 |   点赞0

来源:https://blog.csdn.net/u011541946/category_6887610.html

JavaScript学习笔记14-if语句

x33g5p2x  于2022-03-06 转载在 其他  
字(0.5k)|赞(0)|评价(0)|浏览(546)

本文开始学习if语句,和大部分语言一样,JavaScript 中if语句,基本格式如下:

if(条件为真){

代码块;

}

  1. <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. </head>
  6. <body>
  7. <script type ="text/javascript">
  8. var apples = 35;
  9. var hotdogs = 76;
  10. if (apples < hotdogs){
  11. document.write("yea it worked!");
  12. }
  13. </script>
  14. </body>
  15. </html>

自己修改下数字大小,还有以下条件,测试运行看看。

apples == hotdogs

apples != hotdogs

apples > hotdogs

apples >= hotdogs

apples <= hotdogs

相关文章