I want to change the images of main webpage according to the value sent in javascript file. I have defined div tag in my html file and placed default value for image src. Then I am taking input from user about their mood. Using if else, i compared the value and chose the suitable image to display on my webpage. But, I am unable to change the default value of src tag in my program. I just tried something else and could not find ways to resolve this. Thank you in advance.
NOTE: I am a beginner in JS
home.html
<!DOCTYPE html>
<html>
<head>
<title>Getting Started with</title>
</head>
<body>
<script src='script.js'></script>
<div id = 'feel'>
<img src = "images/dull.jpg">
</div>
</body>
</html>
script.js
var feelingInfo = prompt("How are you feeling? (dull or fresh or sleepy)");
var suitableImage = document.getElementById('feel');
//console.log(feelingInfo);
//Here I want to change the src
if(feelingInfo == "dull"){
suitableImage.innerHTML.src = '"images/dull.jpg">';
}
else if(feelingInfo == "fresh"){
suitableImage.innerHTML.src = '"images/fresh.jpg">';
}
else if(feelingInfo == "sleepy"){
suitableImage.innerHTML.src = '"images/sleepy.jpg">';
}
else{
console.log("Error");
}
Good Morning
So, using single id and wanted to try to connect with other tags with that as well. – cnayak Sep 20 '20 at 13:29