Skip to content
Merged
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
49 changes: 49 additions & 0 deletions Guess The Word/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="hero">
<div id="title">
<h1 id="heading">Guess The Word</h1>
<div id="Difficulty">
<label for="diff-option">Difficulty:</label>
<select name="level" id="diff-option">
<option value="normal">Normal (6 mistakes)</option>
<option value="easy">Easy (8 mistakes)</option>
<option value="hard">Hard (4 mistakes)</option>
</select>
</div>
</div>
<div id="play-arena">
<div id="category">
Category:
<span id="selected-category"></span>
</div>
<div id="hint">
Hint:
<span id="hint-text"></span>
</div>
<div id="blank"></div>
<input
type="text"
id="guessInput"
placeholder="Enter your guess"
autocomplete="off"
/>
<div id="Attempts-counts">
Attempts left:
<span id="count"></span>
</div>
<div id="submit"><button id="submitBtn">Submit</button></div>
<button id="new-word">New word</button>
</div>
<div id="result-arena"></div>
</div>
<script src="script.js"></script>
</body>
</html>
233 changes: 233 additions & 0 deletions Guess The Word/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
const words = [
{
word: "javascript",
category: "Programming",
hint: "A scripting language for the web.",
},
{
word: "python",
category: "Programming",
hint: "A snake and a popular programming language.",
},
{
word: "react",
category: "Programming",
hint: "A JavaScript library for building UIs.",
},
{
word: "algorithm",
category: "Programming",
hint: "A step-by-step procedure to solve a problem.",
},
{
word: "variable",
category: "Programming",
hint: "Used to store data values in a program.",
},

{ word: "elephant", category: "Animal", hint: "The largest land animal." },
{ word: "tiger", category: "Animal", hint: "The national animal of India." },
{
word: "penguin",
category: "Animal",
hint: "A bird that cannot fly but can swim.",
},
{
word: "dolphin",
category: "Animal",
hint: "An intelligent aquatic mammal.",
},
{
word: "kangaroo",
category: "Animal",
hint: "An animal that hops and carries babies in a pouch.",
},

{
word: "pizza",
category: "Food",
hint: "A popular Italian dish with cheese.",
},
{
word: "burger",
category: "Food",
hint: "A sandwich with a patty inside buns.",
},
{
word: "pasta",
category: "Food",
hint: "An Italian dish made with noodles and sauce.",
},
{
word: "sushi",
category: "Food",
hint: "A Japanese dish made with rice and raw fish.",
},
{
word: "biryani",
category: "Food",
hint: "A flavorful rice dish popular in South Asia.",
},

{ word: "mumbai", category: "City", hint: "A coastal city in India." },
{
word: "paris",
category: "City",
hint: "The city of love and the Eiffel Tower.",
},
{ word: "tokyo", category: "City", hint: "The capital of Japan." },
{ word: "newyork", category: "City", hint: "The Big Apple." },
{
word: "london",
category: "City",
hint: "Famous for the Big Ben and the Thames.",
},

{
word: "guitar",
category: "Instrument",
hint: "Has strings and is played with fingers.",
},
{
word: "piano",
category: "Instrument",
hint: "Has keys and is played with fingers.",
},
{
word: "drums",
category: "Instrument",
hint: "Played with sticks and gives rhythm.",
},
{
word: "violin",
category: "Instrument",
hint: "A string instrument played with a bow.",
},
{
word: "flute",
category: "Instrument",
hint: "A wind instrument you blow into.",
},

{ word: "moon", category: "Space", hint: "Earth’s only natural satellite." },
{
word: "sun",
category: "Space",
hint: "The star at the center of our solar system.",
},
{ word: "mars", category: "Space", hint: "The red planet." },
{
word: "galaxy",
category: "Space",
hint: "A system of stars, dust, and gas bound by gravity.",
},
{
word: "comet",
category: "Space",
hint: "An icy body that glows as it passes near the sun.",
},

{
word: "cricket",
category: "Sport",
hint: "A bat-and-ball game popular in India.",
},
{
word: "football",
category: "Sport",
hint: "A game played with a round ball and two goals.",
},
{
word: "chess",
category: "Sport",
hint: "A game of strategy played on a checkered board.",
},
{
word: "tennis",
category: "Sport",
hint: "Played with rackets and a small yellow ball.",
},
{
word: "basketball",
category: "Sport",
hint: "A game where players shoot hoops.",
},

{ word: "rose", category: "Flower", hint: "A symbol of love and romance." },
{ word: "lotus", category: "Flower", hint: "The national flower of India." },
{
word: "sunflower",
category: "Flower",
hint: "Follows the sun across the sky.",
},
{
word: "tulip",
category: "Flower",
hint: "A spring flower often found in the Netherlands.",
},
{
word: "lily",
category: "Flower",
hint: "A fragrant white flower often used in ceremonies.",
},
];
const categoryEl = document.getElementById("selected-category");
const hintEl = document.getElementById("hint-text");
const blankEl = document.getElementById("blank");
const guessInput = document.getElementById("guessInput");
const submitBtn = document.getElementById("submitBtn");
const newWordBtn = document.getElementById("new-word");
const resultEl = document.getElementById("result-arena");
const countEl = document.getElementById("count");
const difficultySelect = document.getElementById("diff-option");
let secretWord = "";
let attempt = 0;

setDifficulty = () => {
const level = difficultySelect.value;
if (level === "easy") attempt = 8;
else if (level === "medium") attempt = 6;
else attempt = 4;
};
startGame = () => {
const random = words[Math.floor(Math.random() * words.length)];
categoryEl.innerHTML = random.category;
hintEl.innerHTML = random.hint;
secretWord = random.word.toLowerCase();
blankEl.innerHTML = "_".repeat(secretWord.length);
resultEl.textContent = "";
setDifficulty();
countEl.textContent = attempt;
guessInput.value = "";
};
guessWord = () => {
const guess = guessInput.value.trim().toLowerCase();
if (!guess || attempt < 1) {
return;
}
if (guess === secretWord) {
resultEl.textContent = `✅ Correct! The word was ${secretWord.toUpperCase()}`;
resultEl.style.color = "var(--sucess)";
} else {
attempt--;
resultEl.textContent = `❌ Wrong! Try again.`;
resultEl.style.color = `var(--error)`;
countEl.textContent = attempt;
if (attempt <= 0) {
resultEl.textContent =
"💀 Game Over! The word was " + secretWord.toUpperCase();
resultEl.style.color = "var(--error)";
}
}
guessInput.value = "";
};
submitBtn.addEventListener("click", () => {
guessWord();
});
guessInput.addEventListener("keydown", (e) => {
if (e.key === "Enter") checkGuess();
});
newWordBtn.addEventListener("click", startGame);
difficultySelect.addEventListener("change", startGame);

startGame();
Loading