LoginSignup
1
1

More than 3 years have passed since last update.

JavaScript勉強日記#1

Last updated at Posted at 2020-11-24

①確認ダイアログボックスの表示

・目的:下記のダイアログボックスを表示する
https://gyazo.com/3da5a0c50544d85af25c1c7cd4adce3b
https://gyazo.com/f9808943633140799071c34fea626e74

index.html
  <script>
   if(window.confirm('ゲームスタート!準備はいいかい?')) {
    console.log('ゲームを開始します!');
  } else {
    console.log('ゲームを終了します。');
  }  
  </script>

window.confirm('message')で表示できた。
alertメソッドとの違いはT/Fでリターンを返してくる事。

②テキストを持ったダイアログを表示
・目的:下記のダイアログの表示
https://gyazo.com/c24d08dedc4a761b0f2faea00317ae3e
https://gyazo.com/67b10557bbb964c2fbcf729268dc9fb0

window.confirm('message')で表示できた。
これは変数を用いる事で保存が可能になる。
例えばlet answer(変数名) = window.confirm('message')と書けばこれ以降answerと書く事でmessageを取得できる。

③入力内容で動作を変更する
・目的:動作を条件分岐させたい

index.html
const answer = window.prompt('ヘルプを見ますか?');
if(answer === 'yes') {
  window.alert('タップでジャンプ、障害物をよけます。');
}

constで生成された変数は後から上書きできない。

1
1
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
1
1