JavaScript基础教程

文章39 |   阅读 23222 |   点赞0

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

JavaScript学习笔记15-if-else语句

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

前面介绍了if语句的,接下来学习else,和其他语言一样,if和else一般一块使用。就像生活中我们做决定,如果什么,那么做什么,否则,做什么。就这么简单,来看看示例。

  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("I like hotdogs!");
  12. }else{
  13. document.write(" I like apples");
  14. }
  15. </script>
  16. </body>
  17. </html>

相关文章