JavaScript基础教程

文章39 |   阅读 11517 |   点赞0

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

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

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

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

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
</head>
<body>
<script type ="text/javascript">
		var apples = 35;
		var hotdogs = 76;
		if (apples < hotdogs){
			document.write("I like hotdogs!");
		}else{
			document.write(" I like apples");
		}
</script>
</body>
</html>

相关文章