JavaScript implements code for inputting the radius of a circle and outputting the circumference, volume and area

The following is the code and running screenshots for inputting the radius of a circle and outputting the circumference, volume and area.

Table of contents

Preface

1. Please enter the radius of the circle and output the circumference, volume and area.

1.1 Operation process and ideas

1.2 Code snippet

1.3 JavaScript statement code

1.4 Running screenshots


Preface

1. If you have a choice, you can quickly search in the directory;

2. The code of this blog post can implement relevant functions according to the requirements of the topic. At the same time, customized settings can be achieved;

3. This article introduces JavaScript code exercises. The software used in this blog is code written by HBuilder X3.7.9. In principle, other software such as DW, VSCode or lower or higher versions of DW are compatible. If you have In principle, software that requires and writes software other than HBX can run normally;

Figure 1 Example of writing software (part)

4. Special note here, because I am using HBX, so it is in web page format. I also pasted the <script> statement separately. If necessary, you can directly copy the <script> statement;

5. The code of this blog post was written by me when I was in school. There are some parts that are not perfectly implemented. Please forgive me and please give me more advice. If you find any problems, please feed them back to me so that I can correct the mistakes and summarize the improvements. , Continuous improvement! 

6. Blog posts usually need to be run in a browser, and a form usually pops up to input values ​​and get the results. This article uses Google Chrome, and it is recommended to use Google Chrome;

7. If there is any infringement, please contact us for deletion;


提示:以下是本篇文章正文内容,下面案例可供参考

1. Please enter the radius of the circle and output the circumference, volume and area.

1.1 Operation process and ideas

This allows a script to pop up on the web page and use formulas to calculate the perimeter and volume. area, and then output the code written for the basic operation. The specific thought process is as follows:

1.2 Code snippet

The code is as follows (example):

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script charset="utf-8";>
			var l,b,v;
			const PI=3.1315926;
			r=prompt("请输入圆的半径:",0);
			l=PI*r*2;
			b=(4/3)*PI*r*r*r;
			v=PI*r*r;
			document.write("圆的周长是:","<h2>",l,"</h2>");
			document.writeln("圆的体积是:","<h2>",b,"</h2>");
			document.write("圆的面积是:","<h2>",v,"</h2>");
		</script>
	</head>
	<body>
	</body>
</html>

1.3 JavaScript statement code

The code is as follows (example):

<script charset="utf-8";>
			var l,b,v;
			const PI=3.1315926;
			r=prompt("请输入圆的半径:",0);
			l=PI*r*2;
			b=(4/3)*PI*r*r*r;
			v=PI*r*r;
			document.write("圆的周长是:","<h2>",l,"</h2>");
			document.writeln("圆的体积是:","<h2>",b,"</h2>");
			document.write("圆的面积是:","<h2>",v,"</h2>");
		</script>

1.4 Running screenshots

The running results are as follows (example):

1.4.1 Browser pop-up form to display results

1.4.2 Display the results after running 

Guess you like

Origin blog.csdn.net/weixin_59042297/article/details/130410427