ランダムテキスト生成アプリ
「レターパックで現金送れはすべて詐欺です」という文章をランダムに並び替えます。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ランダムテキスト生成アプリ</title>
</head>
<body>
<h1>ランダムテキスト生成アプリ</h1>
<p>「レターパックで現金送れはすべて詐欺です」という文章をランダムに並び替えます。</p>
<button onclick="randomize()">生成</button>
<p id="result"></p>
<script>
function randomize() {
const text = "レターパックで現金送れはすべて詐欺です";
const words = text.split(" ");
const scrambledWords = []
// ランダムな順番で単語に並び替える
while (words.length > 0) {
const index = Math.floor(Math.random() * words.length);
scrambledWords.push(words[index]);
words.splice(index, 1);
}
// ランダムに並び替えた単語を連結して出力する
document.getElementById("result").innerHTML = scrambledWords.join(" ");
}
</script>
</body>
</html>