Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ These projects are perfect for anyone who wants to:
| 6๏ธโƒฃ | โœ‚๏ธ **Rock Paper Scissors** | Classic hand game with interactive UI and score tracking. |
| 7๏ธโƒฃ | ๐Ÿ”ด๐ŸŸก **Connect 4** | Drop discs to connect four in a row before your opponent does. |
| 8๏ธโƒฃ | โšก **Typing Test** | Test your typing speed with small quotes. |
| 9๏ธโƒฃ | ๐Ÿงฉ **Sudoku** | Fill the 9ร—9 grid so each row, column and 3ร—3 box contains digits 1โ€“9.
| 9๏ธโƒฃ | ๐Ÿงฉ **Sudoku** | Fill the 9ร—9 grid so each row, column and 3ร—3 box contains digits 1โ€“9. |
| ๐Ÿ”Ÿ | ๐Ÿ’ป **Binary Blitz** | Convert binary numbers to decimal and build your score across ten rounds. |


> Want to add your own game? Fork this repo and bring your creativity to life! ๐ŸŽจ
Expand Down Expand Up @@ -412,4 +413,4 @@ If you find this project helpful:
- ๐Ÿง‘โ€๐Ÿ’ป Contribute your own game or fix bugs
- ๐Ÿ’ฌ Share this project with friends

> โ€œPlay. Code. Learn. Contribute.โ€ โ€” _Hacktoberfest 2025_ ๐Ÿ’ป๐ŸŽ‰
> โ€œPlay. Code. Learn. Contribute.โ€ โ€” _Hacktoberfest 2025_ ๐Ÿ’ป๐ŸŽ‰
42 changes: 42 additions & 0 deletions content/contribution/binary-blitz/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Binary Blitz is a beginner-friendly binary-to-decimal conversion game.">
<title>Binary Blitz</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main class="game-card">
<header>
<p class="eyebrow">Binary conversion challenge</p>
<h1>Binary Blitz</h1>
<p class="instructions">Convert each binary number to decimal. Choose the correct answer before moving to the next round.</p>
</header>

<section class="status-bar" aria-label="Game status">
<p>Question <strong id="question-number">1</strong>/<span id="question-total">10</span></p>
<p>Score <strong id="score">0</strong></p>
</section>

<section id="question-panel" class="question-panel">
<p class="prompt">What is this binary number in decimal?</p>
<p id="binary-number" class="binary-number" aria-live="polite">00000000</p>
<div id="answer-options" class="answer-grid" aria-label="Answer choices"></div>
<p id="feedback" class="feedback" aria-live="polite"></p>
<button id="next-button" class="primary-button" type="button" hidden>Next Question</button>
</section>

<section id="results-panel" class="results-panel" hidden>
<p class="result-icon" aria-hidden="true">๐Ÿ</p>
<h2>Challenge Complete!</h2>
<p id="final-score" class="final-score"></p>
<p id="result-message"></p>
<button id="restart-button" class="primary-button" type="button">Play Again</button>
</section>
</main>

<script src="script.js"></script>
</body>
</html>
158 changes: 158 additions & 0 deletions content/contribution/binary-blitz/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
const TOTAL_QUESTIONS = 10;
const MIN_VALUE = 1;
const MAX_VALUE = 255;

const questionNumberElement = document.querySelector("#question-number");
const questionTotalElement = document.querySelector("#question-total");
const scoreElement = document.querySelector("#score");
const binaryNumberElement = document.querySelector("#binary-number");
const answerOptionsElement = document.querySelector("#answer-options");
const feedbackElement = document.querySelector("#feedback");
const nextButton = document.querySelector("#next-button");
const restartButton = document.querySelector("#restart-button");
const questionPanel = document.querySelector("#question-panel");
const resultsPanel = document.querySelector("#results-panel");
const finalScoreElement = document.querySelector("#final-score");
const resultMessageElement = document.querySelector("#result-message");

let currentQuestion = 1;
let score = 0;
let correctAnswer = 0;
let usedValues = new Set();

function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getUniqueQuestionValue() {
let value;

do {
value = randomInteger(MIN_VALUE, MAX_VALUE);
} while (usedValues.has(value));

usedValues.add(value);
return value;
}

function shuffle(values) {
const shuffledValues = [...values];

for (let index = shuffledValues.length - 1; index > 0; index -= 1) {
const randomIndex = randomInteger(0, index);
[shuffledValues[index], shuffledValues[randomIndex]] = [
shuffledValues[randomIndex],
shuffledValues[index]
];
}

return shuffledValues;
}

function createAnswerChoices(answer) {
const choices = new Set([answer]);

while (choices.size < 4) {
const offset = randomInteger(-18, 18);
const possibleChoice = answer + offset;

if (possibleChoice >= MIN_VALUE && possibleChoice <= MAX_VALUE) {
choices.add(possibleChoice);
}
}

return shuffle([...choices]);
}

function renderQuestion() {
correctAnswer = getUniqueQuestionValue();
const binaryValue = correctAnswer.toString(2).padStart(8, "0");

questionNumberElement.textContent = currentQuestion;
scoreElement.textContent = score;
binaryNumberElement.textContent = binaryValue;
feedbackElement.textContent = "";
feedbackElement.className = "feedback";
nextButton.hidden = true;
answerOptionsElement.replaceChildren();

createAnswerChoices(correctAnswer).forEach((choice) => {
const button = document.createElement("button");
button.type = "button";
button.className = "answer-button";
button.textContent = choice;
button.dataset.value = choice;
button.addEventListener("click", handleAnswer);
answerOptionsElement.append(button);
});
}

function handleAnswer(event) {
const selectedAnswer = Number(event.currentTarget.dataset.value);
const answerButtons = answerOptionsElement.querySelectorAll("button");

answerButtons.forEach((button) => {
button.disabled = true;

if (Number(button.dataset.value) === correctAnswer) {
button.classList.add("correct");
}
});

if (selectedAnswer === correctAnswer) {
score += 1;
scoreElement.textContent = score;
feedbackElement.textContent = "Correct! Nice conversion.";
feedbackElement.classList.add("correct-text");
} else {
event.currentTarget.classList.add("incorrect");
feedbackElement.textContent = `Not quite. The correct answer is ${correctAnswer}.`;
feedbackElement.classList.add("incorrect-text");
}

nextButton.textContent = currentQuestion === TOTAL_QUESTIONS
? "See Results"
: "Next Question";
nextButton.hidden = false;
}

function showResults() {
questionPanel.hidden = true;
resultsPanel.hidden = false;
finalScoreElement.textContent = `${score} out of ${TOTAL_QUESTIONS}`;

if (score === TOTAL_QUESTIONS) {
resultMessageElement.textContent = "Perfect scoreโ€”you are a binary master!";
} else if (score >= 7) {
resultMessageElement.textContent = "Great work! Your binary skills are strong.";
} else if (score >= 4) {
resultMessageElement.textContent = "Good start. A little more practice will sharpen your skills.";
} else {
resultMessageElement.textContent = "Keep practicingโ€”you will get faster with every round.";
}
}

function goToNextQuestion() {
if (currentQuestion === TOTAL_QUESTIONS) {
showResults();
return;
}

currentQuestion += 1;
renderQuestion();
}

function startGame() {
currentQuestion = 1;
score = 0;
usedValues = new Set();
questionTotalElement.textContent = TOTAL_QUESTIONS;
questionPanel.hidden = false;
resultsPanel.hidden = true;
renderQuestion();
}

nextButton.addEventListener("click", goToNextQuestion);
restartButton.addEventListener("click", startGame);

startGame();
Loading