in this javascript when the finalScore and totalScore are displayed I also want to remove the 'const message = "You scored " + score + " points";
// Update the 'results' div using DOM manipulation
const resultsDiv = document.getElementById("results");
resultsDiv.textContent = message;
' message previously displayed in the 'results' div. 'let map; // Declare map globally
let streetLatitude;
let streetLongitude;
let marker; // Define marker globally to make it accessible across functions
let totalScore = 0; // Initialize total points variable
let possibleScore = 0; // Initialize total points variable
let imageIndex = 0; // Initialize image index
let PictureURL; // Define PictureURL at a higher scope level
let Description;
let clickListener; // Store the click listener reference
let roundScores = [];
// Check if there are more images to display
if (imageIndex >= entryCount) {
console.log("No more images to display!");
// Display "Game Over" message
const resultsDiv = document.getElementById("results");
const finalScores = Total Score: ${totalScore} points out of a possible ${possibleScore}<br><br>;
To remove the message previously displayed in the results div, you can simply set the textContent to an empty string before updating the resultsDiv with the new message. Here's how you can modify the code snippet:
javascript
const message = "You scored " + score + " points";
// Update the 'results' div using DOM manipulation
const resultsDiv = document.getElementById("results");
resultsDiv.textContent = ""; // Clear the previous message
resultsDiv.textContent = message;
Add the line resultsDiv.textContent = ""; before setting the textContent to the new message to remove the previous message displayed in the results div.
// Update numberoffeeds div
// Update numberoffeeds div
const numberoffeedsElement = document.getElementById("results");
numberoffeedsElement.textContent = This is a ${entryCount} round game.\nClick on the map where you think this scene is.;
callback(FeatureID);
})
.catch((error) => console.error("Error fetching data: ", error));
}
map = new google.maps.Map(document.getElementById("map"), mapOptions);
// Add a click event listener to the map
clickListener = map.addListener("click", (event) => {
const clickLocation = event.latLng; // Get the latitude and longitude of the click
// Create a new marker
marker = new google.maps.Marker({
position: clickLocation,
map: map, // Set the map where the marker will be displayed
draggable: true, // Set draggable to true
});
// (Optional) Add additional customization to the marker here,
// such as setting an icon or info window
// Remove the click event listener after adding the marker
google.maps.event.removeListener(clickListener);
// Add functionality after clicking the map
createSubmitButton(map, clickLocation);
});
}
//nextbutton
const nextButton = document.createElement("button");
nextButton.id = "nextButton";
nextButton.textContent = "Next"; // Customize button text as needed
nextButton.className = "nextbutton";
// Apply CSS animation class for easy management
nextButton.classList.add("nextButtonAnimation");
// Function to create and add the button
function createSubmitButton(map, clickLocation) {
const buttonsDiv = document.getElementById("buttons");
if (!buttonsDiv) {
console.error("Element with ID 'buttons' not found!");
return;
}
// Get the current marker position when the button is pressed
const markerPosition = marker.getPosition();
// Calculate distance between marker and StreetPoints
const distanceInMeters =
google.maps.geometry.spherical.computeDistanceBetween(
new google.maps.LatLng(streetLatitude, streetLongitude),
markerPosition
);
const roundedDistanceInMeters = Math.floor(distanceInMeters); // Round down to the nearest meter
console.log(
"Distance to StreetPoints: " + roundedDistanceInMeters + " meters"
);
// Adjust points based on distance
let score = 5000 - roundedDistanceInMeters;
if (score < 0) {
score = 0;
}
totalScore += score; // Add current points to total
possibleScore += 5000;
roundScores.push(score);
// Set the polyline on the map
polyline.setMap(map);
marker.setDraggable(false);
// Replace the buttons
buttonsDiv.replaceChild(nextButton, submitButton);
// Set map bounds to encompass marker and polyline
const bounds = new google.maps.LatLngBounds(); // Use google.maps here
bounds.extend({ lat: streetLatitude, lng: streetLongitude });
bounds.extend(polyline.getPath().getAt(1));
map.fitBounds(bounds);
});
// Function to update the image and description
function updateImage(FeatureID, PictureURL) {
const infoDiv = document.getElementById("info");
const infoHTML = Description;
infoDiv.innerHTML = infoHTML;
const paintingDiv = document.getElementById("painting");
const imageHTML =
'';
console.log("Image URL:", imageHTML); // Log the image URL to the console
paintingDiv.innerHTML = imageHTML;
}
// Add click event for the ‘Next’ button
nextButton.addEventListener("click", () => {
// Increment the image index to fetch the next image
imageIndex++;
// Fetch the next image from the JSON file and update the painting div
fetchStreetDetails((fetchedFeatureID) => {
updateImage(fetchedFeatureID, PictureURL);
// Create a LatLng object representing the new position
const newLatLng = new google.maps.LatLng(21.382325, -8.170154652);
map.setCenter(newLatLng);
map.setZoom(3);
const message = "Where do you think this scene is?";
// Add click event listener back to the map
google.maps.event.clearListeners(map, "click"); // Clear existing click listeners
clickListener = map.addListener("click", (event) => {
const clickLocation = event.latLng;
// Create a new marker
marker = new google.maps.Marker({
position: clickLocation,
map: map,
draggable: true,
});
// Remove the click event listener after adding the marker
google.maps.event.removeListener(clickListener);
createSubmitButton(map, clickLocation);
});
// Update the 'results' div using DOM manipulation
const resultsDiv = document.getElementById("results");
resultsDiv.textContent = message;
});