当前位置:网站首页>js中判断奇偶的函数,求圆面积的函数
js中判断奇偶的函数,求圆面积的函数
2022-06-27 07:20:00 【I am the sun?】
定义一个函数,判断是否为偶数,如果是则返回true,不是则返回false
传统方法:
代码:
<!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>
运行结果:
简化方法(a%2==0本来就是布尔判断了):
<!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>
运行结果:
定义一个函数,可以根据半径计算圆的面积,并返回计算结果
<!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("圆的面积是:" + result);
</script>
</head>
<body>
</body>
</html>
运行结果:
边栏推荐
- mysql关于自增和不能为空
- 通过uview让tabbar根据权限显示相应数量的tabbar
- 从5秒优化到1秒,系统飞起来了...
- 正斜杠反斜杠的由来
- [leetcode] day90 the element with the smallest K in the binary search tree
- R language calculates Spearman correlation coefficient in parallel to speed up the construction of co occurrence network
- JDBC transaction commit case
- Hutool symmetric encryption
- Window right click management
- (已解决) MINet 进行测试时报错如下 raise NotImplementedError
猜你喜欢

【软件工程】山东大学软件工程复习提纲

Solve the problem of win10 wsl2 IP change

2022 CISP-PTE(一)文件包含

SQL injection bypass (I)

Unsafe中的park和unpark
![[openairinterface5g] rrcsetupcomplete for RRC NR resolution](/img/61/2136dc37b98260e09f3be9979492b1.jpg)
[openairinterface5g] rrcsetupcomplete for RRC NR resolution

用XGBoost迭代读取数据集

Yarn create vite reports an error 'd:\program' which is neither an internal or external command nor a runnable program or batch file

From 5 seconds to 1 second, the system flies

POI replacing text and pictures in docx
随机推荐
[Kevin's third play in a row] is rust really slower than C? Further analyze queen micro assessment
(resolved) NPM suddenly reports an error cannot find module 'd:\program files\nodejs\node_ modules\npm\bin\npm-cli. js‘
[Software Engineering] software engineering review outline of Shandong University
Write an example of goroutine and practice Chan at the same time
POI export excle
How torch. gather works
通过uview让tabbar根据权限显示相应数量的tabbar
高薪程序员&面试题精讲系列116之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
Nature、science、cell旗下刊物
Idea method template
sql sever列名或所提供值的数目与表定义不匹配
JDBC事务提交事例
Solve the problem of win10 wsl2 IP change
manim 数学引擎
SQL injection bypass (I)
Idea one click log generation
Oppo interview sorting, real eight part essay, abusing the interviewer
(已解决) npm突然报错 Cannot find module ‘D:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js‘
C# 请问怎么在更新数据库时候调用line与rows
R language analyzing wine data