// Get the like button and unlike button elements const likeButton = document.getElementById('like-button'); const unlikeButton = document.getElementById('unlike-button');
// Set the initial state of the like button and unlike button based on the value of the "like" cookie if (getCookie('like') === 'true') { likeButton.style.display = 'none'; unlikeButton.style.display = 'inline-block'; } else { likeButton.style.display = 'inline-block'; unlikeButton.style.display = 'none'; }
// Add a click event listener to the like button likeButton.addEventListener('click', function() { // Set the "like" cookie to "true" setCookie('like', 'true', 365); // Update the button display likeButton.style.display = 'none'; unlikeButton.style.display = 'inline-block'; });
// Add a click event listener to the unlike button unlikeButton.addEventListener('click', function() { // Set the "like" cookie to "false" setCookie('like', 'false', 365); // Update the button display likeButton.style.display = 'inline-block'; unlikeButton.style.display = 'none'; });
// Function to get a cookie value function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); }
// Function to set a cookie function setCookie(name, value, days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); const expires = `expires=${date.toUTCString()}`; document.cookie = `${name}=${value};${expires};-Path=/`; }
The U.S. is a country of 50 states covering a vast swath of North America, with Alaska in the northwest and Hawaii extending the nation’s presence into the Pacific Ocean. Major Atlantic Coast cities are New York, a global finance and culture center, and capital Washington, DC. Midwestern metropolis Chicago is known for influential architecture and on the west coast, Los Angeles' Hollywood is famed for filmmaking.