Files
mincojs/basics.html
2025-10-30 20:14:04 +09:00

138 lines
2.8 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MincoJS — 基礎の森</title>
<style>
body {
font-family: monospace;
background: #fdfaf7;
color: #333;
margin: 20px;
}
pre {
width: 100%;
height: 280px;
border: 1px solid #aaa;
background: #fff;
overflow-y: auto;
padding: 8px;
white-space: pre-wrap;
}
textarea {
width: 100%;
height: 160px;
font-family: monospace;
}
#error {
border: 1px solid #c33;
background: #fee;
color: #900;
padding: 8px;
white-space: pre-wrap;
min-height: 1.5em;
}
#inputField {
width: 100%;
padding: 4px;
font-family: monospace;
border: 1px solid #aaa;
}
button { margin: 4px; }
footer {
margin-top: 2em;
font-size: 0.9em;
color: #666;
border-top: 1px solid #ccc;
padding-top: 0.5em;
}
</style>
</head>
<body>
<h2>📘 MincoJSサンプル基礎の森</h2>
<p>JavaScriptの基本を少しずつ試してみようにゃ。</p>
<textarea id="code">// 1. ハローワールド
print("Hello, world!");
// 2. 1から10までの数字
for (let i = 1; i <= 10; i++) {
print(i);
}
// 3. 1から10までの2乗
for (let i = 1; i <= 10; i++) {
print(i + " の2乗 = " + (i * i));
}
// 4. 掛け算九九
for (let i = 1; i <= 9; i++) {
let row = "";
for (let j = 1; j <= 9; j++) {
row += (i * j).toString().padStart(2, " ") + " ";
}
print(row);
}
// 5. 条件分岐input使用
// 入力欄に "cat" や "dog" を入れて実行してみよう!
let word = input();
if (word === "cat") {
print("🐱 にゃーん!");
} else if (word === "dog") {
print("🐶 わんわん!");
} else {
print("🤔 その子は知らないにゃ。");
}
</textarea><br>
<label for="inputField">入力欄:</label>
<input id="inputField" type="text" value="cat" placeholder="例: cat / dog"><br>
<button onclick="runCode()">▶ 実行</button>
<button onclick="clearOutput()">🧹 クリア</button>
<h3>出力</h3>
<pre id="output"></pre>
<h3>エラー</h3>
<div id="error"></div>
<footer>
🏡 <a href="list.html">MincoJS Village に戻る</a>
</footer>
<script>
const output = document.getElementById('output');
const errorBox = document.getElementById('error');
const inputField = document.getElementById('inputField');
function print(...args) {
output.textContent += args.join(' ') + "\n";
output.scrollTop = output.scrollHeight;
}
function input() {
return inputField.value;
}
function clearOutput() {
output.textContent = '';
errorBox.textContent = '';
}
function runCode() {
const code = document.getElementById('code').value;
try {
errorBox.textContent = '';
new Function('print', 'input', code)(print, input);
} catch (e) {
errorBox.textContent = '❌ ' + e.message;
}
}
</script>
</body>
</html>