Hello,
I am currently beginning the Odin Project and have progressed to the JavaScript basics portion. Following this guide (https://developer.mozilla.org/en-US/Learn/Getting_started_with_the_web/JavaScript_basics)
After spending some time attempting to get the code to prompt you for a name / give the user an individualized welcome message with no success, I am here.
I believe that I followed the instructions to the letter but have been unable to get either the prompt function, welcome message, or change user button to work. I even tried to copy and past the code but the issue still persists.
I will attempt to copy and paste the code below and see if you folks could help spot the error!
From: index.html:
'''
<title>My test page</title>
A delightful trip into the Green Mountains with Dorian Yablin!
Here Dorian and I were cheering on top of Jay Peak Mountain because of the beautiful weather and fantastic ski conditions we were experiencing!
- A week long get away with a condo on the mountain!
- One of our many trips together that leaves me filled with joy and happiness!
Jay Peak Resort!
Change user
<script src="scripts/main.js"></script>
'''
Here is the main.js:
var myImage = document.querySelector('img');
myImage.onclick = function() {
var mySrc = myImage.getAttribute('src');
if(mySrc === 'images/jay_peak_trip.jpg') {
myImage.setAttribute ('src','images/vienna_trip.jpg');
} else {
myImage.setAttribute ('src','images/jay_peak_trip.jpg');
}
}
var myButton = document.querySelector('button');
var myHeading = document.querySelector('h1');
function setUserName() {
var myName = prompt('Please enter your name.');
localStorage.setItem('name', myName);
myHeading.textContent = 'Welcome!, ' + myName;
}
if(!localStorage.getItem('name')) {
setUserName();
} else {
var storedName = localStorage.getItem('name');
myHeading.textContent = 'Welcome Back! ' + storedName;
}
myButton.onclick = function() {
setUserName();
}
Sorry if this is just a wall of syntax, but I simply don't know how else to go about finding this error. Any and all tips / advice is appreciated! Thank you for your time!