Parts of the code I contributed
Timer Function
function resetTimer() {
startTime = new Date().getTime();
clearInterval(timerInterval);
timerInterval = setInterval(updateTimer, 10);
}
function stopTimer() {
clearInterval(timerInterval);
}
function updateTimer() {
const currentTime = new Date().getTime();
let elapsedTime = currentTime - startTime;
hours = Math.floor(elapsedTime / 3600000);
elapsedTime -= hours * 3600000;
minutes = Math.floor(elapsedTime / 60000);
elapsedTime -= minutes * 60000;
seconds = Math.floor(elapsedTime / 1000);
milliseconds = elapsedTime - (seconds * 1000);
updateTimerDisplay();
}
function updateTimerDisplay() {
const timerElement = document.getElementById('timer');
timerElement.textContent = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}.${padMilliseconds(milliseconds)}`;
}
function pad(num) {
return num.toString().padStart(2, '0');
}
function padMilliseconds(num) {
return num.toString().padStart(3, '0');
}
Letter Count (Length off of Answer)
NOTE: My specific portion begins after the first “else” command. the “checkGuess” function is part of Eashaan’s contribution.
function checkGuess() {
const userInput = document.getElementById('user-input').value.trim();
if (userInput.toLowerCase() === currentCountry.toLowerCase()) {
document.getElementById('result').innerText = `Congratulations! You guessed it right in ${attempts + 1} attempts.`;
stopTimer();
} else {
attempts++;
const lengthDifference = currentCountry.length - userInput.length;
if (lengthDifference > 0) {
document.getElementById('result').innerText = `Try again. Your answer is ${lengthDifference} letters too short.`;
} else {
document.getElementById('result').innerText = `Try again. Your answer is ${Math.abs(lengthDifference)} letters too long.`;
}
}
}
Additional: Images and Country Lists
I also put (in list form) many of the countries that were in our project. I also spent hours finding images for each flag and silhouette image for each country.
Some country examples of this are sampled below.
const countries = [
"United States",
"United Kingdom",
"Canada",
"Australia",
"France",
"Germany",
"Italy",
"Japan",
"China",
"India",
"Russia",
"Brazil",
"Mexico",
"Spain",
"South Africa",
"Argentina",
"Turkey",
"Greece",
"Netherlands",
"South Korea",
"Denmark",
"Ireland",
"New Zealand",
"Singapore",
"Thailand",
"Vietnam",
"Indonesia",
"Philippines",
"Saudi Arabia",
"Qatar",
"Israel",
];
Country Silhouette Images
const countryImages = {
"United States": "images/US.png",
"United Kingdom": "images/UK.png",
"Canada": "images/Canada.png",
"Australia": "images/Australia.png",
"France": "images/France.png",
"Germany": "images/Germany.png",
"Italy": "images/Italy.png",
"Japan": "images/Japan.png",
"China": "images/China.png",
"India": "images/India.png",
"Russia": "images/Russia.png",
"Brazil": "images/Brazil.png",
"Mexico": "images/Mexico.png",
"Spain": "images/Spain.png",
"South Africa": "images/SouthAfrica.png",
"Argentina": "images/Argentina.png",
"Turkey": "images/Turkey.png",
"Greece": "images/Greece.png",
"Netherlands": "images/Netherlands.png",
"South Korea": "images/SouthKorea.jpeg",
"Denmark": "images/Denmark.png",
"Ireland": "images/Ireland.png",
"New Zealand": "images/NewZealand.png",
"Singapore": "images/Singapore.png",
"Thailand": "images/Thailand.png",
"Vietnam": "images/Vietnam.png",
"Indonesia": "images/Indonesia.png",
"Philippines": "images/Philippines.png",
"Saudi Arabia": "images/SaudiArabia.png",
"Qatar": "images/Qatar.png",
"Israel": "images/Israel.png",
Flag Images
const countryFlagImages = {
"United States": "images/USFlag.png",
"United Kingdom": "images/UKFlag.png",
"Canada": "images/CanadaFlag.png",
"Australia": "images/AustraliaFlag.png",
"France": "images/FranceFlag.png",
"Germany": "images/GermanyFlag.png",
"Italy": "images/ItalyFlag.png",
"Japan": "images/JapanFlag.png",
"China": "images/ChinaFlag.png",
"India": "images/IndiaFlag.png",
"Russia": "images/RussiaFlag.png",
"Brazil": "images/BrazilFlag.png",
"Mexico": "images/MexicoFlag.png",
"Spain": "images/SpainFlag.png",
"South Africa": "images/SouthAfricaFlag.png",
"Argentina": "images/ArgentinaFlag.png",
"Egypt": "images/EgyptFlag.png",
"Turkey": "images/TurkeyFlag.png",
"Greece": "images/GreeceFlag.png",
"Netherlands": "images/NetherlandsFlag.png",
"Switzerland": "images/SwitzerlandFlag.png",
"South Korea": "images/SouthKoreaFlag.png",
"Sweden": "images/SwedenFlag.png",
"Norway": "images/NorwayFlag.png",
"Denmark": "images/DenmarkFlag.png",
"Ireland": "images/IrelandFlag.png",
"New Zealand": "images/NewZealandFlag.png",
"Singapore": "images/SingaporeFlag.png",
"Malaysia": "images/MalaysiaFlag.png",
"Thailand": "images/ThailandFlag.png",
"Vietnam": "images/VietnamFlag.png",
"Indonesia": "images/IndonesiaFlag.png",
"Philippines": "images/PhilippinesFlag.png",
"Saudi Arabia": "images/SaudiArabiaFlag.png",
"Qatar": "images/QatarFlag.png",
"Israel": "images/IsraelFlag.png",
"Jordan": "images/JordanFlag.png",
"Lebanon": "images/LebanonFlag.png"
};