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 1 year has passed since last update.

Javascript if文でメッセージを出し分ける

Last updated at Posted at 2022-04-07

はじめに

javascritのif文の書き方を学ぶ

参考書

ゴール

if文でダイアログのボタンごとにメッセージを出し分ける

手順

ダイアログボックスを表示してOKまたはキャンセルでメッセージを出し分ける
<script>
'use strict';

if (window.confirm('ゲームを開始します。準備はいいですか?')){
 console.log('ゲームスタート!'); //OKを選択するとtrueの分岐へ
} else {
 console.log('ゲームオーバー・・・'); //キャンセルを選択するとfalseの分岐へ
}
</script>

メモ

window.confirmこれで確認ダイアログボックスが出せる

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?