当前位置:网站首页>JS计算圆的周长和面积
JS计算圆的周长和面积
2022-04-22 23:10:00 【加辣椒了吗?】
题目: 计算圆的周长和面积
最近刚学习js,就把书上的习题做一下。
<!DOCTYPE html >
<html>
<head>
</head>
<body>
<!--计算圆的周长和面积-->
<div>
<p>周长:<input id="zc" type="text" value="周长" ></p>
<p>面积:<input id="mj" type="text" value="面积" ></p>
</div>
<script>
var a = parseFloat(prompt("请输入圆的半径:"))
const p = 3.14 //因为Π是不变的,所以我把它设为常量
var b = 2*p*a//周长
var c = a*p*a//面积
if(Boolean(a)){
//判断是否为空
if( isNaN(a)){
//判断是否为数值
alert("输入错误")
}
else{
document.getElementById("zc").value = b.toFixed(2)//toFixed(2)化简小数点后两位
document.getElementById("mj").value = c.toFixed(2)
}
}
</script>
</body>
</html>
运行结果:


小白的思路和方法,简单就好

版权声明
本文为[加辣椒了吗?]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44797539/article/details/105982684
边栏推荐
猜你喜欢

【Vmware】Vmware ESXI 6.7 安装

登录功能&新增文章功能的测试点提取以及测试用例编写

News Express I mobtech passed the "special safety evaluation" of China Academy of information and communications

visio文本框输入公式

How to treat, Kwai, know and other platforms will display the user's IP's functions locally?

SQL语言详解

Pytorch 卷积核填充和步幅、多输入多输出通道、池化层

英语 | Day13、14 x 句句真研每日一句(平行、嵌套结构)

如何快速转载CSDN中的博客

How to modify the QR code style when scanning the code and logging in the background management system of enterprise wechat
随机推荐
辰视工业级机器视觉 | 焊缝检测解决方案
Login function & test point extraction of new article function and test case writing
MySQL调整配置:不区分大小写
js中对Array进行遍历
RPC details
Cap theory
Online yaml to XML tool
Detailed explanation of SQL language
ansible作业1
How to install cadence software
【论文代码复现】Translating Embeddings for Modeling Multi-relational Data中TransE代码实现+遇到的错误
从proc查询uid
How to open MT5 account and what products can MT5 trade?
常用搜索引擎及语法
public speaking
记录使用PageHelper时,使用Example添加排序失效问题
旅行箱指纹锁方案pcb电路板方案
[hctf 2018] Unicode spoofing of admin
Shell script command results are saved to variables with line breaks
2022-4-22作业-MySQL单表查询