<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>モールス信号通信アプリ</title>
</head>
<body>
<h1>モールス信号通信アプリ</h1>
<form>
<label for="text">文字を入力してください:</label>
<input type="text" id="text">
<button type="button" onclick="convert()">変換</button>
</form>
<div id="result"></div>
<script>
const morseCode = {
"a": ".-", "b": "-...", "c": "-.-.", "d": "-..", "e": ".", "f": "..-.", "g": "--.", "h": "....", "i": "..", "j": ".---",
"k": "-.-", "l": ".-..", "m": "--", "n": "-.", "o": "---", "p": ".--.", "q": "--.-", "r": ".-.", "s": "...", "t": "-",
"u": "..-", "v": "...-", "w": ".--", "x": "-..-", "y": "-.--", "z": "--..", " ": "/", "1": ".----", "2": "..---", "3": "...--",
"4": "....-", "5": ".....", "6": "-....", "7": "--...", "8": "---..", "9": "----.", "0": "-----"
};
function convert() {
const textInput = document.getElementById("text").value.toLowerCase();
let result = "";
for (let i = 0; i < textInput.length; i++) {
const char = textInput.charAt(i);
if (morseCode[char]) {
result += morseCode[char] + " ";
} else {
result += " ";
}
}
document.getElementById("result").innerHTML = `「${textInput}」をモールス信号に変換したものは「${result.trim()}」です。`;
}
</script>
</body>
</html>
※ジョーク要素はありません。