Lichen5221 / Report-Daily

記錄每日上課內容與作業。
0 stars 0 forks source link

2021-05-11 #22

Open Lichen5221 opened 3 years ago

Lichen5221 commented 3 years ago

閱讀 Javascript 大全(犀牛 6E )

刪除一個陣列元素會在陣列上留下一個「洞」,而且不會改變陣列長度。

JS101 綜合題目練習 Lv 1

印出 1 ~ 9

for 迴圈

for (let i = 1; i <= 9; i++) {
  console.log(i)
}

while 迴圈

var n = 1
while (n <= 9) {
  console.log(n);
  n++;
}

印出 1 ~ n

for 迴圈

function copy(n) {
  for (let i = 1; i <= n; i++) {
    console.log(i)
  }
}

copy(9)
copy(30)

while 迴圈

var i = 1
function copy(n) {
  while (i <= n) {
    console.log(i);
    i++;
  }
}

copy(5)

寫一個能夠印出 n 個 * 的函式

for 迴圈

let s = ''
function star(n) {
  for (let i = 1; i <= n; i++){
    s += '*'
  }
  console.log(s)
}

star(10)

while 迴圈

let s = ''
let i = 1
function star(n) {
  while (i <= n) {
    s += '*';
    i++;
  }
  console.log(s)
}

star(5)

寫一個能回傳 n 個 * 的函式

for 迴圈

let s = ''
function star(n) {
  for (let i = 1; i <= n; i++){
    s += '*'
  }
  return s
}

star(10)

while 迴圈

let s = ''
let i = 1
function star(n) {
  while (i <= n) {
    s += '*';
    i++;
  }
  return s
}

console.log(star(5))

判斷大小寫

function isUpperCase(str) {
  let ascii = str.charCodeAt(0)
  if (ascii >= 65 && ascii <= 90) {
    return true
  } return false
}

回傳第一個大寫字母以及它的 index