구구단
<script>
let gugudan = "";
let num = "";
const dan = () => {
gugudan = "";
for (let i = 1; i <= 9; i++) {
gugudan += `${num} * ${i} = ${parseInt(num)*i}<br>`;
}
}
</script>
<style>
input[type="text"]{
width: 50px;
}
</style>
<table border="1">
<tr>
<th>출력 단수</th>
<td>
<input type="text" bind:value={num}/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" on:click={dan} value="구구단"/>
</td>
</tr>
<tr>
<td colspan="2">
<div>{@html gugudan}</div>
</td>
</tr>
</table>
가위바위보
<script>
let com = "";
let result = "";
const arr = ["가위", "바위", "보"];
let mine = "가위";
function game(){
var rnd = parseInt(""+Math.random()*3);
com = arr[rnd];
if (mine==com){
result = "비김"
} else if((mine=="가위" && com=="보") || (mine=="바위" && com=="가위") || (mine=="보" && com=="바위")){
result = "이김"
} else {
result = "짐"
}
}
</script>
<table border="1">
<tr>
<td>나</td>
<td>
<select bind:value={mine}>
{#each arr as rps}
<option value="{rps}">
{rps}
</option>
{/each}
</select>
</td>
</tr>
<tr>
<td>컴퓨터</td>
<td>
{com}
</td>
</tr>
<tr>
<td>결과</td>
<td>
{result}
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="게임시작" on:click={game}>
</td>
</tr>
</table>