当前位置:网站首页>JS to judge the odd and even function and find the function of circular area

JS to judge the odd and even function and find the function of circular area

2022-06-27 07:35:00 I am the sun?

Define a function , Judge whether it is even , If so, return true, If not, return to false

traditional method :
Code :

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
	<script type="text/javascript">
		function isOdd(a){
			if(a % 2 == 0)
			return true;
			else
			return false;
		}
		var result = isOdd(1);
		document.write(result);
	</script>
</head>
<body>
	
</body>
</html>

Running results :
 Insert picture description here
Simplify the method (a%2==0 It was Boole's judgment ):

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
	<script type="text/javascript">
		function isOdd(a){
			return a % 2 == 0;
		}
		var result = isOdd(112);
		document.write(result);
	</script>
</head>
<body>
	
</body>
</html>

Running results :
 Insert picture description here

Define a function , You can calculate the area of a circle based on its radius , And return the calculation results

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
	<script type="text/javascript">
		function area(r){
			return 3.14 * r * r;
		}
		 var result = area(5);
		 document.write(" The area of a circle is :" + result);
	</script>
</head>
<body>
	
</body>
</html>

Running results :
 Insert picture description here

原网站

版权声明
本文为[I am the sun?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270720099231.html