javascript - 如何编写一个函数,返回一个宽为 5,高为 8 的矩形的周长?
问题描述
我目前的尝试如下,但我什至不确定将 5 和 8 的输入放在哪里。任何帮助/建议都会受到赞赏。
function rectPerimeter(width, height) {
return 2 * width + 2 * height;
}
console.log(rectPerimeter)
解决方案
执行以下操作:
function rectPerimeter(width, height) {
return 2 * width + 2 * height;
}
// define width
let w = 5; // change value as you need
// define height
let h = 8; // change value as you need
// call rectPerimeter with params i.e. width and height
console.log(rectPerimeter(w, h));
您还可以捕获返回值,然后将其显示到控制台:
function rectPerimeter(width, height) {
return 2 * width + 2 * height;
}
// define width
let w = 5; // change value as you need
// define height
let h = 8; // change value as you need
// call rectPerimeter with params i.e. width and height
let perimeter = rectPerimeter(w, h);
// show perimeter to console
console.log(perimeter);
推荐阅读
- python - 为什么类型(对象)返回
代替 ? - python - scipy.sparse.coo_matrix 上的元素操作(例如模)?
- oracle - Oracle 查询 - 计算日期和时间差 - 重叠
- flutter - Flutter:Flutter Emulator 无法打开相机(flutter_emulator:5554)
- python - sqlite ImportError:没有名为_sqlite3 Google App Engine的模块
- docker - docker内的Nginx反向代理不支持上游的端口设置
- r - 在 R 中模拟动态范围以按任意函数进行过滤
- xamarin - 如何在触发按钮 15 秒后使标签不可见?
- ms-access - 是否可以在查询和表之间使用联合查询?
- python - 生产订单中每个已启动工单之间的仓库路线