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 5 years have passed since last update.

javascript超入門(2020/06/15)

0
Posted at

条件分岐(else if)

if文の条件式がfalseになるとelse以降が実行される。else後ろにまた別のif文を繋げることができる。

sample.js
if(answer=== 'yes'){
  処理1
} else if(answer==='no'){
  処理2
} else {
  処理3
}

文字列を整列に変換する

sample.js
parseInt(変換したい文字列);

プロンプトに入力されたテキストはそれが仮に「3」であっても数値ではなく文字として認識される。parseIntメソッドを使えばプロンプトの入力内容を整数に変換できる。

比較演算子

演算子 意味
a === b aとbが同じときtrue
a !== b aとbが同じでないときtrue
a < b aがbより小さいときtrue
a <= b aがb以下のときtrue
a > b aがbより大きいときtrue
a >= b aがb以上のときtrue

論理演算子

演算子 意味
条件式a && 条件式b aとbが両方trueのとき、全体の評価結果がtrue
条件式a ll 条件式b aかbの少なくともどちらか1つがtrueのとき、全体の評価結果がtrue
! 条件式a aがtrueでないとき、評価結果がtrue

while文

sample.js
while(条件式){
  //条件式がtrueのときここが繰り返し実行される
}

同じような処理を実行するのが繰り返し。while文は()内の条件式がtrueである限り、{}内の処理を繰り返し実行する。

文字列連結

プログラム  +の機能 結果
console.log(16 + 70); 足し算 86
console.log(name + 'さん'); 文字列連結 田中さん
console.log((16 + 70) + '個'); 足し算、文字列連結 86個

ファンクション

ファンクションとは()内のパラメータを受け取り、何らかの加工をして、その結果を呼び出し元に返すもの。

パラメータを受け取り→何らかの加工をして→結果を呼び出し元に返す

ファンクションの呼び出し

sample.js
ファンクション名要求されたパラメータ

total(8000)

  

ファンクションの作成

sample.js
function ファンクション名(要求するパラメータ)
   具体的な処理内容

  

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?