6
5

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.

ズンドコキヨシ with JavaScript

Last updated at Posted at 2016-03-14

日本人プログラマーの登竜門、ズンドコキヨシです。
JavaScriptですと95文字で書いてしまう人もいるようですが、参加することに意義があるということで自分なりに書いてみました。

zundoko.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>Zundoko</title>
</head>
<body>
    <script>
        const ZUNDOKO = ["ズン", "ドコ"];
        const FEVER = 4;
        
        var zun = 0;
        var kiyoshi = false;
        
        while (! kiyoshi) {
            var sound = ZUNDOKO[Math.floor(Math.random() * ZUNDOKO.length)];
            document.write(sound);
            
            if (sound == ZUNDOKO[0]) {zun++;}
            
            switch (true) {
                case zun < FEVER:
                    if (sound == ZUNDOKO[1]) {
                        zun = 0;
                    }
                    break;
                case zun == FEVER:
                    if (sound == ZUNDOKO[1]) {
                        kiyoshi = true;
                        continue;
                    }
                    break;
                case zun > FEVER:
                    zun = 0;
                    break;
            }
        }
        document.write("キ・ヨ・シ!");
    </script>
</body>
</html>

文字列「ズンズンズンズンドコ」を予め用意して答え合わせをするやり方ではなく、「ズン」の連続発生数が4回になった直後に「ドコ」がきたらキ・ヨ・シ!を出力というロジックです。

猛者プログラマの方々のズンドコキヨシはこちらにまとまっています。
http://qiita.com/shunsugai@github/items/971a15461de29563bf90

6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?