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

ファルコン・パンチの表示順をランダムにする

Last updated at Posted at 2020-04-03

作成にあたって

友人がpythonを用いてターミナル上動作するこれを作っていたので、僕はhtmlとjs使って作成してみました。
動けばいいだけだったので1つのファイルにまとめて書いています。

コード

index.html
<!doctype html>
<html>
<head>
<title>ファルコン・パンチ</title>

<script type="text/javascript">
    function exchangeText() {
        var text = document.forms.id_form.id_textBox.value.split("");
        target = document.getElementById("output");
        if(exchange(text)){
            target.innerText = exchange(text);
        }else{
            target.innerText = "";
        }
    }
    // 文字の順番を入れ替える
    function exchange(text) {
        for(i=0; i<text.length; i++){
            var rand = Math.floor(Math.random()*text.length);
            var tmp = text[i];
            text[i] = text[rand];
            text[rand] = tmp;
        }
        var output;
        for(i=0; i<text.length; i++){
            if(output){
                output = output + text[i];
            }else{
                output = text[i];
            }
        }
        return output;
    }
</script>
</head>

<body>
    <p><b>ファルコンのうんちぶり</b></p>
    <form name="form" id="id_form" action="">
        <input name="textBox" id="id_textBox" type="text" value="ファルコン・パンチ" />
        <input type="button" value="入れ替え" onclick="exchangeText()" />
    </form>
    <div id="output"></div>

</body>
</html>

おわりに

実務経験が少ないため、どうかけば可読性が向上するのか等コメント頂ければ幸いです。

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