Skip to content

Instantly share code, notes, and snippets.

@ihsanfaisal
Created January 20, 2026 01:27
Show Gist options
  • Select an option

  • Save ihsanfaisal/6cfaa14ace51fbf12b48cd1aefb731f3 to your computer and use it in GitHub Desktop.

Select an option

Save ihsanfaisal/6cfaa14ace51fbf12b48cd1aefb731f3 to your computer and use it in GitHub Desktop.
loop dan if
<!doctype html>
<html lang="id">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rekap Nilai Kelas</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f0f0f0;
height: 100vh;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.card {
background: white;
padding: 25px;
border-radius: 10px;
width: 380px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
margin-top: 0;
}
button {
width: 100%;
padding: 10px;
margin-top: 10px;
border-radius: 6px;
border: none;
background: #3498db;
color: white;
font-size: 15px;
cursor: pointer;
}
button:hover {
background: #2980b9;
}
#hasil {
margin-top: 15px;
font-size: 14px;
line-height: 1.5;
}
.ringkasan {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid #ccc;
font-weight: bold;
}
</style>
</head>
<body>
<div class="card">
<h2>📊 Rekap Nilai Kelas</h2>
<p>Jumlah siswa: <b>10 orang</b></p>
<button onclick="proses()">Proses Nilai</button>
<div id="hasil"></div>
</div>
<script>
function proses() {
const JUMLAH_SISWA = 10
let total = 0
let lulus = 0
let tidakLulus = 0
let output = ''
// LOOP UTAMA
for (let i = 1; i <= JUMLAH_SISWA; i++) {
let nilai = Number(prompt('Masukkan nilai siswa ke-' + i))
total += nilai
if (nilai >= 75) {
output += 'Siswa ke-' + i + ': ' + nilai + ' (LULUS)<br>'
lulus++
} else {
output += 'Siswa ke-' + i + ': ' + nilai + ' (TIDAK LULUS)<br>'
tidakLulus++
}
}
let rata = total / JUMLAH_SISWA
output += `
<div class="ringkasan">
Total nilai: ${total}<br>
Rata-rata: ${rata.toFixed(2)}<br>
Jumlah lulus: ${lulus}<br>
Jumlah tidak lulus: ${tidakLulus}
</div>
`
document.getElementById('hasil').innerHTML = output
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment