0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScript4,for文 初心者向け

Last updated at Posted at 2020-12-13

4,for文
JS(JavaScript)でfor文(繰り返し処理)を行ってみましょう!
配列との組み合わせについても紹介しています。

文の繰り返し

for (let i = 0; i < 10; i++) {
  console.log(i);  
}

表示させるのは
0123456789

let i = 0;
iが0になり

i < 10;
0から10になるまで繰り返す

i++ (略語で i = i + 1) 0+1 1+1 2+1…
0から1足していく
※ I— なら1づつ引いていく

1回繰り返す毎に{ } の中身を実行する

for (let i = 0; i < 10; i++) {
  let li = document.createElement("li");
  li.textContent = i;
  document.getElementById("number").appendChild(li);
  console.log(i);
}

let li = document.createElement("li");
htmlにli をjsで生成し

li.textContent = i;
liに文字列を入れる

.appendChild(li);
子要素にして()に入れる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?