1、页面中有一个按钮要求,能实现点击这个按钮弹出显示按钮中的值。
2、使用js打印出1000以内的水仙花数
3、使用函数完成一个calculate函数,该函数接收x、c、y三个参数,x和y为数字,c为运算符范围为(+、-、*、/),要求函数返回x c y的结果。例如x为1,c为+,y为2,则结果为3。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button onclick="alert('hello World')">点击按钮</button>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var a, b, c;
for (var i = 100; i < 1000; ++i) {
a = i % 10;
b = ((i / 10) % 10);
b = parseInt(b);
c = i / 100;
c = parseInt(c);
if (i == a * a * a + b * b * b + c * c * c)
document.write('水仙花数:'+i + "<br />");
}
</script>
</head>
<body>
</body>
</html>
function alertInfo(msg) {
alert(msg);
}
function calculate(x, c, y) {
if ('+' == c) {
return x+y;
}
if ('-' == c) {
return x-y;
}
if ('*' == c) {
return x*y;
}
if ('/' == c) {
return x/y;
}
}
alertInfo(calculate(1,'+',100));
在这里插入代码片