alexander 2025-11-20 17:53:00 +07:00
commit 01fad1e317
3 changed files with 242 additions and 148 deletions

View File

@ -1,148 +0,0 @@
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile Editor</title>
<style>
body {
font-family: 'Times New Roman', Times, serif;
background-color: #f8f9fa;
margin: 40px;
}
h2 {
text-align: center;
}
form {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 8px rgba(0,0,0,0.2);
width: 400px;
margin: auto;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
}
input {
width: 100%;
padding: 8px;
margin-top: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
margin-top: 15px;
padding: 8px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
#tambah {
background-color: #007bff;
color: white;
}
#reset {
background-color: #6c757d;
color: white;
}
#daftar {
margin-top: 30px;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 8px rgba(0,0,0,0.2);
width: 400px;
margin: 30px auto;
}
.profile-card {
border-bottom: 1px solid #ccc;
padding: 10px 0;
}
.hapus-btn {
background-color: #dc3545;
color: white;
border: none;
border-radius: 5px;
padding: 5px 10px;
cursor: pointer;
}
</style>
</head>
<body>
<h2>Profile Editor</h2>
<form id="profileForm">
<label>Nama:</label>
<input type="text" id="nama" placeholder="Masukkan nama" required>
<label>Tanggal Lahir:</label>
<input type="date" id="tgl" required>
<label>Kota:</label>
<input type="text" id="kota" placeholder="Masukkan kota" required>
<button type="button" id="tambah" onclick="tambahProfil()">Tambah Profile</button>
<button type="reset" id="reset">Reset Form</button>
</form>
<div id="daftar">
<h3>Daftar Profile</h3>
<div id="listProfile"></div>
</div>
<script>
let profiles = [];
function tambahProfil() {
const nama = document.getElementById("nama").value.trim();
const tgl = document.getElementById("tgl").value;
const kota = document.getElementById("kota").value.trim();
if (!nama || !tgl || !kota) {
alert("Semua data harus diisi!");
return;
}
// Hitung umur
const lahir = new Date(tgl);
const sekarang = new Date();
let umur = sekarang.getFullYear() - lahir.getFullYear();
const bulan = sekarang.getMonth() - lahir.getMonth();
if (bulan < 0 || (bulan === 0 && sekarang.getDate() < lahir.getDate())) {
umur--;
}
// Simpan ke array
profiles.push({ nama, tgl, kota, umur });
tampilkanProfile();
document.getElementById("profileForm").reset();
}
function tampilkanProfile() {
let output = "";
profiles.forEach((p, index) => {
output += `
<div class="profile-card">
<strong>${p.nama}</strong><br>
Umur: ${p.umur} tahun<br>
Tanggal Lahir: ${p.tgl}<br>
Kota: ${p.kota}<br>
<button class="hapus-btn" onclick="hapusProfile(${index})">Hapus</button>
</div>
`;
});
document.getElementById("listProfile").innerHTML = output;
}
function hapusProfile(i) {
profiles.splice(i, 1);
tampilkanProfile();
}
</script>
</body>
</html>

View File

242
ody git.js Normal file
View File

@ -0,0 +1,242 @@
// Simple Blackjack implementation
const SUITS = ['♠','♥','♦','♣'];
const RANKS = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
const dealerHandEl = document.getElementById('dealer-hand');
const playerHandEl = document.getElementById('player-hand');
const dealerValueEl = document.getElementById('dealer-value');
const playerValueEl = document.getElementById('player-value');
const balanceEl = document.getElementById('balance');
const betInput = document.getElementById('bet-input');
const betBtn = document.getElementById('bet-btn');
const currentBetEl = document.getElementById('current-bet');
const hitBtn = document.getElementById('hit');
const standBtn = document.getElementById('stand');
const doubleBtn = document.getElementById('double');
const newRoundBtn = document.getElementById('new-round');
const messageEl = document.getElementById('message');
let deck = [];
let dealer = [];
let player = [];
let dealerHidden = true;
let balance = 1000;
let currentBet = 0;
let inRound = false;
// Membuat deck kartu
function makeDeck() {
deck = [];
for (let s of SUITS) {
for (let r of RANKS) {
deck.push({ suit: s, rank: r });
}
}
}
// Shuffle
function shuffle() {
for (let i = deck.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[deck[i], deck[j]] = [deck[j], deck[i]];
}
}
// Nilai kartu
function cardValue(card) {
if (card.rank === 'A') return 11;
if (['J','Q','K'].includes(card.rank)) return 10;
return Number(card.rank);
}
// Nilai total tangan
function handValues(hand) {
let total = 0;
let aceCount = 0;
for (let c of hand) {
total += cardValue(c);
if (c.rank === 'A') aceCount++;
}
while (total > 21 && aceCount > 0) {
total -= 10;
aceCount--;
}
return total;
}
// Render kartu
function renderHand(container, hand, hideFirst = false) {
container.innerHTML = '';
hand.forEach((card, i) => {
const div = document.createElement('div');
div.className = 'card';
// warna merah ♥ ♦
if (card.suit === '♥' || card.suit === '♦') {
div.classList.add('red');
}
if (hideFirst && i === 0) {
div.className = "card back";
div.textContent = "🂠";
} else {
div.innerHTML = `
<div>${card.rank}${card.suit}</div>
<div>${card.rank}${card.suit}</div>
`;
}
container.appendChild(div);
});
}
// Update UI
function updateUI() {
renderHand(playerHandEl, player, false);
renderHand(dealerHandEl, dealer, dealerHidden);
dealerValueEl.textContent = dealerHidden ? "?" : handValues(dealer);
playerValueEl.textContent = handValues(player);
balanceEl.textContent = balance;
currentBetEl.textContent = currentBet;
hitBtn.disabled = !inRound;
standBtn.disabled = !inRound;
doubleBtn.disabled = !inRound;
if (!inRound) {
messageEl.textContent = "Pasang taruhan untuk mulai.";
}
}
// Mulai ronde
function startRound() {
if (inRound) return;
const bet = Number(betInput.value);
if (bet <= 0 || bet > balance) {
messageEl.textContent = "Taruhan tidak valid!";
return;
}
balance -= bet;
currentBet = bet;
makeDeck();
shuffle();
dealer = [deck.pop(), deck.pop()];
player = [deck.pop(), deck.pop()];
dealerHidden = true;
inRound = true;
messageEl.textContent = "Permainan dimulai!";
updateUI();
// Natural blackjack
if (handValues(player) === 21) {
playerStand();
}
}
// Player hit
function playerHit() {
if (!inRound) return;
player.push(deck.pop());
updateUI();
if (handValues(player) > 21) {
dealerHidden = false;
messageEl.textContent = "Kamu bust! Dealer menang.";
inRound = false;
updateUI();
}
}
// Player stand
function playerStand() {
if (!inRound) return;
dealerHidden = false;
while (handValues(dealer) < 17) {
dealer.push(deck.pop());
}
const pv = handValues(player);
const dv = handValues(dealer);
if (dv > 21 || pv > dv) {
messageEl.textContent = "Kamu menang!";
balance += currentBet * 2;
} else if (pv === dv) {
messageEl.textContent = "Seri!";
balance += currentBet;
} else {
messageEl.textContent = "Dealer menang!";
}
currentBet = 0;
inRound = false;
updateUI();
}
// Double down
function playerDouble() {
if (!inRound) return;
if (balance < currentBet) {
messageEl.textContent = "Saldo tidak cukup untuk double!";
return;
}
balance -= currentBet;
currentBet *= 2;
player.push(deck.pop());
updateUI();
if (handValues(player) > 21) {
dealerHidden = false;
messageEl.textContent = "Bust saat double! Dealer menang.";
inRound = false;
return updateUI();
}
playerStand();
}
// Reset game
newRoundBtn.addEventListener('click', () => {
balance = 1000;
currentBet = 0;
dealer = [];
player = [];
deck = [];
inRound = false;
dealerHidden = true;
messageEl.textContent = "Bank di-reset.";
updateUI();
});
// Events
betBtn.addEventListener('click', startRound);
hitBtn.addEventListener('click', playerHit);
standBtn.addEventListener('click', playerStand);
doubleBtn.addEventListener('click', playerDouble);
// Keyboard shortcut
window.addEventListener('keydown', e => {
if (e.key === 'h') playerHit();
if (e.key === 's') playerStand();
if (e.key === 'd') playerDouble();
if (e.key === 'Enter') startRound();
});
updateUI();