- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
// sphere.js #2
// This script calculates the volume of a sphere.
// Function called when the form is submitted.
// Function performs the calculation and returns false.
function calculate() {
'use strict';
// For storing the volume:
var volume;
// Task 1: Get a reference to the form element:
var radius = document.getElementById("radius");
// Add an "if" statement here to
// make sure there is a reference
if (radius) {
//Task #2: Add an "if" to make sure the value is positive:
if (radius > 0) {
// Task #3: Perform the calculation:
volume = (4/3)*(22/7)*(Pow(radius,3));
//HINT: the formula for the volume of a sphere is V=(4/3)*(pi)*(radius cubed)
// Format the volume:
volume = volume.toFixed(4);
// Task #4: Display the volume:
document.getElementById("volume").id ="volume";
//Hint: use the same method as in the radius variable assignment call above
} //End if
} end if radius
// Return false to prevent submission:
return false;
} // End of calculate() function.
// Function called when the window has been loaded.
// Function needs to add an event listener to the form.
function init() {
'use strict';
document.getElementById('theForm').onsubmit = calculate;
} // End of init() function.
window.onload = init;
我正在尝试编写一个脚本来计算球体的体积。这是一项家庭作业,所以这就是为什么所有这些评论都在那里。它基本上告诉我该怎么做。
嗯,我尽我所知遵循了它,但我仍然收到错误。我得到的错误是第 30 行上的“SyntaxError: Missing ; before statements”。这告诉我要放一个 ;在“结束如果”之前。我猜这不是错误。我猜公式是错误的。
最佳答案
这是计算球体体积的公式:
考虑到这一点,
function volumeOfSphere(radius) {
return (4/3)*Math.PI*Math.pow(radius,3);
}
console.log('The volume of a sphere with a radius of 5 is: '+volumeOfSphere(5));
此外,请不要使用 22/7
作为 pi 的估计值,请使用 Math.PI
另一方面,您的代码无法正常工作的原因是 end if
不是 javascript 代码。您应该删除它,然后重新测试您的代码。
这是一个工作 fiddle :https://jsfiddle.net/qm6uaapu/
关于javascript - 尝试编写一个javascript程序来计算球体的体积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33273410/
我正在尝试让这段代码计算盒子的表面积和体积。它编译但不输出正确的数据。我认为问题可能出在 void Box::零件内,但碰壁了。或者它可能是 Height = Height 但我无法以任何其他方式让它
我需要一个使用 kinect 计算 body 体积(以立方米为单位)的算法。我知道我可以提取云和深度框架(通过使用骨架 NUI 的一些方法隔离 body )但我不知道如何从这个矩阵计算体积值。导出卷
我是 d3 的新手,并试图根据节点之间的连接数使链接的宽度动态化。比方说,我们有: "links": [ { "source": a, "target": b},
我要渲染 3D 数据,它是一个一维数组。此数据在将进行可视化的同一程序中预先计算。数据表示统一的 3D 网格。网格的每个单元格都由一个 vector 组成。 GridSize = dx * dy *
我尝试在 jupyter notebook 中使用 mayavi 渲染体积来测试下面的示例 from mayavi import mlab mlab.init_notebook() x, y, z =
我尝试了几种不同的方法。我需要使用继承来扩展这些类。每次我运行该程序时,它都会输出 0.0 的体积和面积。半径显示正确。输出在底部。 public class Base_HW04Q1 { pu
我参与了一个项目,我需要根据体积的一系列图像渲染 3D 体积。这些图像是通过多种技术创建的,因此它们是所讨论对象的垂直切片。 数据集类似于this question , 但提问者正在寻找 Matlab
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines准则。它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,
我想知道是否有任何基于 numpy 的工具可以: 给定一个二值输入的 3D numpy 图像,找到它的凸包; 并返回索引列表或此 3D 凸包内的体素(3D 像素)的类似物。 一种可能是使用skimag
我要使用 Matlab 从灰度图像集创建一个 3D 体积。一组包含二维灰度图像的连续量化切片。我仍然认为自己是 Matlab 的菜鸟,但这是我目前的想法: 为 3D 体积创建一个空白空间。 在每张图片
我有一个 3D 体积和一个 2D 图像以及两者之间的近似映射(没有倾斜的仿射变换,已知缩放,旋转和平移近似已知并且需要拟合)。因为这个映射有错误,我想进一步将 2D 图像注册到 3D 体积。我以前没有
更新: 我创建了一个文档齐全的 ipython 笔记本。如果您只想要代码,请查看第一个答案。 问题 我有一个 40x40x40 体积的灰度值。这需要旋转/移动/剪切。 这是一组有用的齐次变换:http
看似简单的问题,没有图像处理/处理经验的人其实没那么容易。 我不只是想将 2D 阵列堆叠在一起,而是通过合并多个由空白分隔的二进制 2D 切片来创建 3D 体积。 例子: 用零定义一个 3D 矩阵:
我非常沮丧,因为几个小时后,我似乎无法在 python 中进行看似简单的 3D 插值。在 Matlab 中,我所要做的就是 Vi = interp3(x,y,z,V,xi,yi,zi) 使用 scip
我是一名优秀的程序员,十分优秀!