The code is:
代码是:
var x = 32;
var y = 44;
var radius = 5;
var centerX = 0;
var centerY = 0;
var width = 600;
var height = 400;
function setup(width, height) {
centerX = width/2;
centerY = height/2;
}
function computeDistance(x1, y1, x2, y2) {
var dx = x1 - x2;
var dy = y1 - y2;
var d2 = (dx * dx) + (dy * dy);
var d = Math.sqrt(d2);
return d;
}
function circleArea(r) {
var area = Math.PI * r * r;
return area;
}
setup(width, height);
var area = circleArea(radius);
var distance = computeDistance(x, y, centerX, centerY);
alert("Area: " + area);
alert("Distance: " + distance);
Also, Which local variable(s) shadows the global variable(s)?
此外,哪个局部变量会影响全局变量?
My answer
Arguments: width, height, radius, x, y, centerX, centerY, “Area: ” + area, “Distance: ”+ distance, d2.
参数:宽度,高度,半径,x,y,centerX,centerY,“面积:”+区域,“距离:”+距离,d2。
Parameters: width, height, x1, y1, x2, y2, r
参数:宽度,高度,x1,y1,x2,y2,r
Local Variables: dx, dy, d2, d, area*
局部变量:dx,dy,d2,d,area *
Global Variables: x, y, radius, centerX, centerY, width, height, area, distance
全局变量:x,y,radius,centerX,centerY,width,height,area,distance
*area shadows the Global variable area.
*区域遮蔽全局变量区域。
But in the book answer: d2 was not given as an argument, maybe there forgot it or something... I want to know whether my answer is correct.
但是在书中回答:d2并没有作为论据,也许是忘了它或者什么......我想知道我的答案是否正确。
1 个解决方案
#1
Your answer looks correct. The book may just have been looking for the arguments, parameters, and variables from of the functions defined on the page. It seems you out-smarted them. You could perhaps submit it to them as a correction because your answer is technically correct.
你的答案看起来是对的本书可能只是在页面上定义的函数中查找参数,参数和变量。看起来你太聪明了。您可以将它作为更正提交给他们,因为您的答案在技术上是正确的。
#1
Your answer looks correct. The book may just have been looking for the arguments, parameters, and variables from of the functions defined on the page. It seems you out-smarted them. You could perhaps submit it to them as a correction because your answer is technically correct.
你的答案看起来是对的本书可能只是在页面上定义的函数中查找参数,参数和变量。看起来你太聪明了。您可以将它作为更正提交给他们,因为您的答案在技术上是正确的。