---
# System prepended metadata

title: input output

---

# input output

```
提示:用if判斷是否為負值與大小是否超過100
//input
cal(-2);
cal(100);
cal(101);
//output
//2
//100
//0
```
答案：
```javascript=
function cal(num) {
  if (num < 0) {
    console.log(Math.abs(num))
  }
  else if (num > 100) {
    num = 0
    console.log(num)
  }
  else console.log(num)
}
```

===
```
提示：
 -可不用迴圈，可用陣列取值方式
 -次方後賦值

// input
let ary1 = [3, 6, 9]
let ary2 = [2, 5, 10]

calc(ary1, 2)
calc(ary2, 3)

// output
// [9, 36, 81]
// [8, 125, 1000]
```

答案:
```javascript=
1.
function cal(num){
  if (num % 2 == 0) {
    if (num <= 0) {
      console.log(-num);
    } else {
      console.log(num);
    }
  } else {
    console.log(0);
  }
}

2.
calc = (arr, num) => {
  let arr2 = [];
  arr.forEach(num1 => {
    arr2.push(num1**num)
  })
  console.log(arr2)
}

3.
function calc(ary, power) {
  ary[0] **= power
  ary[1] **= power
  ary[2] **= power
  console.log(ary)
}
```