Skip to content
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f936e95
Validate empty player names (fixes #1)
iboml Feb 11, 2026
a63654b
Fix delete word functionality (fixes #2)
Feb 11, 2026
c4d2491
Merge pull request #11 from ibrahimgit05/bugfix/empty-player-names
ibrahimgit05 Feb 11, 2026
8443bf6
Prevent same player names (fixes #2)
iboml Feb 11, 2026
602d2b3
Merge pull request #12 from ibrahimgit05/bugfix/same-player-names
ibrahimgit05 Feb 11, 2026
66195a2
Fix score assigned to correct player (fixes #3)
iboml Feb 11, 2026
ddf40d6
Merge pull request #13 from ibrahimgit05/bugfix/wrong-score-assignment
ibrahimgit05 Feb 11, 2026
b79fe2e
Prevent adding empty words (fixes #4)
iboml Feb 11, 2026
eb2e31f
Merge pull request #14 from ibrahimgit05/bugfix/empty-word-validation
ibrahimgit05 Feb 11, 2026
b5478fc
Validate words contain only letters (fixes #5)
iboml Feb 11, 2026
83418ef
Merge branch 'bugfix/delete-word-not-working' of https://github.com/i…
Feb 11, 2026
98f2003
Merge pull request #15 from ibrahimgit05/bugfix/word-validation-lette…
ibrahimgit05 Feb 11, 2026
09a2936
Merge pull request #16 from ibrahimgit05/bugfix/delete-word-not-working
iuv1u Feb 11, 2026
6b75d8e
Fix theme toggle dark mode activation (fixes #6)
Feb 12, 2026
fb83793
Fix lives counter calculation (fixes #7)
Feb 12, 2026
9c4e102
Fix wrong guesses display bug (fixes #8)
Feb 12, 2026
6eb9315
Fix wrong letters display to show only incorrect guesses (fixes #3)
Feb 12, 2026
7dbbd53
Merge pull request #17 from ibrahimgit05/bugfix/wrong-guesses-display
iuv1u Feb 12, 2026
eb9de7b
Merge branch 'main' of https://github.com/ibrahimgit05/devops-hangman
Feb 12, 2026
0ab837b
Fix lives counter display to correctly show remaining lives (fixes #9)
Feb 12, 2026
a8faafb
Merge pull request #18 from ibrahimgit05/bugfix/lives-counter
iuv1u Feb 12, 2026
6ee8a73
Merge branch 'main' of https://github.com/ibrahimgit05/devops-hangman
Feb 12, 2026
fc2e671
Fix theme toggle to properly activate dark mode (fixes #10)
Feb 12, 2026
c501cdc
Merge pull request #19 from ibrahimgit05/bugfix/theme-toggle
iuv1u Feb 12, 2026
e9161f2
Fix edit word to save updated value (fixes #7)
Feb 12, 2026
7a856a2
Merge branch 'main' into bugfix/edit-word-save
iuv1u Feb 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@ document.addEventListener('DOMContentLoaded', function() {
});

function toggleTheme() {
const body = document.body;
const themeIcon = document.querySelector('.theme-icon');

// Toggle dark-mode class on body
body.classList.toggle('dark-mode');

// Update icon
if (themeIcon.textContent === '🌙') {
body.classList.toggle('dark-mode');

if (body.classList.contains('dark-mode')) {
themeIcon.textContent = '☀️';
} else {
themeIcon.textContent = '🌙';
}
}


function switchTab(tabName) {
const tabs = document.querySelectorAll('.tab-content');
tabs.forEach(tab => tab.classList.remove('active'));
Expand Down Expand Up @@ -95,6 +104,16 @@ function addWord() {
const input = document.getElementById('newWord');
const word = input.value.trim().toUpperCase();

if (!word) {
alert('Please enter a word!');
return;
}

if (!/^[A-Z]+$/.test(word)) {
alert('Words can only contain letters A-Z!');
return;
}

wordBank.push(word);
input.value = '';
saveWordBank();
Expand All @@ -104,14 +123,16 @@ function addWord() {
function editWord(index) {
const newWord = prompt('Edit word:', wordBank[index]);
if (newWord) {
wordBank.splice(index, 1);
saveWordBank();
displayWordBank();
wordBank[index] = newWord.toUpperCase(); // replace old word with new
saveWordBank(); // save updated word bank to localStorage
displayWordBank(); // refresh UI
}
}


function deleteWord(index) {
if (confirm('Are you sure you want to delete this word?')) {
wordBank.splice(index, 1);
saveWordBank();
displayWordBank();
}
Expand All @@ -136,8 +157,17 @@ function startGame() {
const p1Name = document.getElementById('player1Name').value.trim();
const p2Name = document.getElementById('player2Name').value.trim();

gameState.player1.name = p1Name || 'Player 1';
gameState.player2.name = p2Name || 'Player 2';
if (!p1Name || !p2Name) {
alert('Both player names are required!');
return;
}
if (p1Name === p2Name) {
alert('Player names must be different!');
return;
}

gameState.player1.name = p1Name;
gameState.player2.name = p2Name;

document.getElementById('player1Display').textContent = gameState.player1.name;
document.getElementById('player2Display').textContent = gameState.player2.name;
Expand Down Expand Up @@ -214,12 +244,12 @@ function updateWrongLetters() {
if (wrong.length === 0) {
wrongLettersDiv.textContent = 'None yet';
} else {
wrongLettersDiv.textContent = gameState.guessedLetters.join(', ');
wrongLettersDiv.textContent = wrong.join(', ');
}
}

function updateLives() {
const livesLeft = gameState.maxWrong - gameState.wrongGuesses + 1;
const livesLeft = gameState.maxWrong - gameState.wrongGuesses;
document.getElementById('livesLeft').textContent = livesLeft;
}

Expand Down Expand Up @@ -285,18 +315,18 @@ function gameWon() {
gameState.gameActive = false;

if (gameState.currentPlayer === 1) {
gameState.player2.score += 10;
document.getElementById('score2').textContent = gameState.player2.score;
} else {
gameState.player1.score += 10;
document.getElementById('score1').textContent = gameState.player1.score;
} else {
gameState.player2.score += 10;
document.getElementById('score2').textContent = gameState.player2.score;
}

const statusDiv = document.getElementById('gameStatus');
const statusMsg = document.getElementById('statusMessage');

const winnerName = gameState.currentPlayer === 1 ?
gameState.player2.name : gameState.player1.name;
gameState.player1.name : gameState.player2.name;

statusMsg.textContent = `🎉 ${winnerName} won! The word was: ${gameState.currentWord}`;
statusDiv.classList.add('show', 'winner');
Expand Down