So I'm trying to make another image appear after clicking on any of the three images, but for some reason the image doesn't appear if I click on any image. If possible, can someone please explain what I'm missing or doing wrong. I know I can use an if else statement but I'm trying to use a different approach.
var figElement = document.getElementById("placeholder");
var imgSource = document.getElementById("image");
var figCap = document.querySelector("figcaption");
//function to display the first picture
function pic1() {
imgSource.src = "images/trunk-bay.jpg";
imgSource.alt = "Elevated view of Trunk Bay beach on St. John";
figElement.style.display = "block";
figCap.textContent = "Trunk Bay in St. John";
}
//function to display the second picture
function pic2() {
imgSource.src = "images/sanjuan.jpg";
imgSource.alt = "Elevated view of Elevated view of San Juan coast";
figElement.style.display = "block";
figCap.textContent = "Coast of San Juan";
}
//function to display the third picture
function pic3() {
imgSource.src = "images/curacao.jpg";
imgSource.alt = "The blue waters of Curacao";
figElement.style.display = "block";
figCap.textContent = "Curacao";
}
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<link rel='stylesheet' href="css/styles.css">
</head>
<script src="scripts/script.js"></script>
<body>
<div id="container">
<header>
<h1>Visit the Caribbean</h1>
</header>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#">Places</a></li>
<li><a href="#">Gallery</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<main>
<p>The Caribbean boasts several island hotspots for your perfect getaway! Enjoy crystal clear waters, sandy white beaches, and never-ending sun. Click the pictures below for a larger view.</p>
<figure>
<img src="images/trunk-bay-thumb.jpg" alt="Elevated view of Trunk Bay beach on St. John" onclick='pic1()'>
<img src="images/sanjuan-thumb.jpg" alt="Elevated view of San Juan coast" onclick='pic2()'>
<img src="images/curacao-thumb.jpg" alt="The blue waters of Curacao" onclick='pic3()'>
</figure>
<figure id="placeholder">
<img src="image" alt="placeholder" id="image">
<figcaption></figcaption>
</figure>
</main>
<footer>
</footer>
</div>
</body>
</html>