Game tebak angka dengan Javascript

Risman
Risman
Apr 27 · 2 min read
<!DOCTYPE html>
<head>
<title>tebak angka</title>
</head>
<body>
<div>
<button>1</button>
<button>2</button>
<button>3</button>
<br style="clear:both">
<button>4</button>
<button>5</button>
<button>6</button>
<br style="clear:both">
<button>7</button>
<button>8</button>
<button>9</button>
</div>
</body>
</html>
.button {
width: 70px;
height: 70px;
background-color: silver;
border: 2px solid black;
padding: 0 10px;
margin: 5px;
cursor: pointer;
}

body {
text-align: center;
}
var angka = Math.floor(Math.random() * 9) + 1;
var angka = Math.floor(Math.random() * 9) + 1;
var random = 'button' + angka;
var jumlah = 0;
var ketemu = 'belum';
function answer(id) {
var jwb = 'Jawaban benar adalah = ' + angka;
var e = document.getElementById(id);
e.innerHTML = jwb;
if (e.style.display == 'none' || e.style.display == '') {
e.style.display = 'block';
} else {
e.style.display = 'none';
}
}
function a(id) {
if (random == id) {
document.getElementById(id).style.background = 'green';
jumlah++;
document.getElementById('jml_klik').innerHTML =
'jumlah tebakan = ' + jumlah;
ketemu = 'sudah';
if (ketemu == 'sudah' && jumlah <= 3) {
document.getElementById('menang').innerHTML = 'Selamat Anda Benar!!!';
}
} else {
document.getElementById(id).style.background = 'red';
jumlah++;
document.getElementById('jml_klik').innerHTML =
'jumlah tebakan = ' + jumlah;
if (ketemu == 'belum' && jumlah >= 3) {
alert('maaf anda gagal tebakan akan di acak kembali');
location.reload();
}
}
}
Risman

Written by

Risman

just free follow me on github https://github.com/rismanss

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade