Javascript Modal Issues

Tell us what’s happening:
I’m having trouble with having multiple different modals on a page. I have created different ids for each modal on my review page, but the content defaults to the same for all of them (even though they have different content in the html). Help much appreciated!

I’m pretty new to Javascript and copy & pasted the code from W3SChools.

Thanks!

Your code so far
Javascript:

// BTN ONE JAVASCIPT START
        
        // Get the modal
        var modal = document.getElementById("myModal");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        }
        
    // BTN ONE JAVASCRIPT END
        
    // BTN TWO JAVASCRIPT START

     // Get the modal
        var modal = document.getElementById("myModal2");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn2");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        }
        
     // BTN TWO JAVASCRIPT END
        
    // BTN THREE JAVASCRIPT START
           // Get the modal
        var modal = document.getElementById("myModal3");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn3");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        }
        
    // BTN THREE JAVASCRIPT END
        
        
    // BTN FOUR JAVASCRIPT START
             // Get the modal
        var modal = document.getElementById("myModal4");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn4");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        } 
    // BTN FOUR JAVASCRIPT END
        
        
    // BTN FIVE JAVASCRIPT START
              // Get the modal
        var modal = document.getElementById("myModal5");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn5");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        }
    // BTN FIVE JAVASCRIPT END
        
        
    // BTN SIX JAVASCRIPT START
          // Get the modal
        var modal = document.getElementById("myModal6");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn6");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        }
    // BTN SIX JAVASCRIPT END
        
    // BTN SVN START
        
    
          // Get the modal
        var modal = document.getElementById("myModal7");

        // Get the button that opens the modal
        var btn = document.getElementById("myBtn7");

        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on the button, open the modal
        btn.onclick = function() {
        modal.style.display = "block";
        }

        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
    modal.style.display = "none";
        }

        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
        if (event.target == modal) {
        modal.style.display = "none";
    }
        }
        
        //BTN SVN END

HTML:

  <!-- REVIEW BOX 0NE START -->                      
                <div class="rvw-blurb-one">
                    
                <img src="ftlol-imgs/my-sweet-audrina-rvw.jpg" alt="black cover for v.c andrews novel my sweet audrina. an eerie house in purples and reds" class="rvw-img">
                    <p class="rvw-score">
                       
                        Title: My Sweet Audrina
                        <br>
                        Author: V.C Andrews
                        
                        <br>
                        Score: <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                        <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold"> 
                        
                        
                    
                    </p>
                    
                   <!-- Trigger/Open The Modal -->
                    <button id="myBtn" class="btn-one">Read review</button>

                    <!-- The Modal -->
                    <div id="myModal" class="modal">

                    <!-- Modal content -->
                    <div class="modal-content">
                    <span class="close">&times;</span>
                
                        
        <h1>My Sweet Audrina</h1>
                        <p>
                        
         Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
                            
      <br>                      
        Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
        <br>
        The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

                    </p>
                </div>

</div> 
        

                </div> 
                
      <!-- REVIEW BOX ONE END -->          
    <!-- REVIEW BOX TWO START -->     
        <div class="rvw-blurb-two">
          <img src="ftlol-imgs/drinking-coffee-elsewhere-rvw.jpg" alt="cover for zz packer's collection of short stories; drinking coffee elsewhere. light background with black and brown text" class="rvw-img">
                    
             <p class="rvw-score">
            Title: Drinking Coffee Elsewhere
            <br>
            Author: ZZ Packer
                        
            <br>
            Score: <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold"> 
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                
            </p>
                    
                    
                    
          <!-- Trigger/Open The Modal -->
                    <button id="myBtn2" class="btn-two">Read review </button>

                    <!-- The Modal -->
                    <div id="myModal2" class="modal">

                    <!-- Modal content -->
                    <div class="modal-content">
                    <span class="close">&times;</span>
                
                        
                 <h1>Drinking Coffee Elsewhere</h1>
                        <p>
                        
            Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

            The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
                            
      <br>                      
            Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
<br>
                       
        <br>
                            <br>
                            <br>
                            
            The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

                    </p>
                </div>

</div> 
                
            </div>
             
    <!-- REVIEW BOX TWO END -->   
                
    <!--REVIEW BOX THREE START -->
                <div class="rvw-blurb-three">
                    
         <img src="ftlol-imgs/mancalledove-rvw.jpg" alt="an illustration of an old white man facing away, with a farmer's cap on and a cat by his side. the cover for fredrik backman's novel a man called ove" class="rvw-img">
                    
             <p class="rvw-score">
            Title: A Man Called Ove
            <br>
            Author: Fredrik Backman
                        
            <br>
            Score: <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                 
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                 
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                    </p>
                    
                
                 <!-- Trigger/Open The Modal -->
                    <button id="myBtn3" class="btn-three">Read review</button>

                    <!-- The Modal -->
                    <div id="myModal" class="modal">

                    <!-- Modal content -->
                    <div class="modal-content">
                    <span class="close">&times;</span>
                
                        
                 <h1>A Man Called Ove</h1>
                        <p>
                        
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
                            
      <br>                      
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
<br>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

                    </p>
                </div>

</div> 
                
                
                
                </div>
     <!-- REVIEW BOX THREE END -->       
    
    <!-- REVIEW BOX FOUR START -->
                <div class="rvw-blurb-four">
            
                    <img src="ftlol-imgs/smallgreatthings-rvw.jpg" alt="a minimal cover for jodie piccoult's novel small great things, with a white background and some multi-coloured square shapes" class="rvw-img">
                    
                           
             <p class="rvw-score">
            Title: Small Great Things
            <br>
            Author: Jodi Picoult 
            <br>           
        
            Score: <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                    </p>
                
                 <!-- Trigger/Open The Modal -->
                    <button id="myBtn4" class="btn-four">Read review</button>

                    <!-- The Modal -->
                    <div id="myModal" class="modal">

                    <!-- Modal content -->
                    <div class="modal-content">
                    <span class="close">&times;</span>
                
                        
                 <h1>Small Great Things</h1>
                        <p>
                        
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
                            
      <br>                      
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
<br>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.

                    </p>
                </div>

</div> 
                
                
                </div>
       <!-- REVIEW BOX FOUR END -->         

    <!-- REVIEW BOX FIVE START -->        
                <div class="rvw-blurb-five"> 
                    
                    <img src="ftlol-imgs/its-kind-of-rvw.jpg" alt="brightly coloured cover for ned vizzini's book it's kind of a funny story. featuring an illlustration of the back of a head outlined with map shapes within" class="rvw-img">
                    
                           
                <p class="rvw-score">
                    Title: It's Kind of a Funny Story 
                <br>
                Author: Ned Vizzini
                <br>    
        
                Score: <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                    
                <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                    
                <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
                    
            
                
                    </p>
                
                 <!-- Trigger/Open The Modal -->
                    <button id="myBtn5" class="btn-five">Read review</button>

                    <!-- The Modal -->
                    <div id="myModal" class="modal">

                    <!-- Modal content -->
                    <div class="modal-content">
                    <span class="close">&times;</span>
                
                        
                 <h1>It's Kind of a Funny Story </h1>
                        <p>
                        

                    </p>
                </div>

</div> 
                
                
                </div>
                
    <!-- REVIEW BOX FIVE END -->
    
    <!-- REVIEW BOX SIX START -->
        <div class="rvw-blurb-six"> 
            
            <img src="ftlol-imgs/grief-is-the-rvw.jpg" alt="cover for grief is the thing with feathers, by max porter. feauturing a black crow on a beige background" class="rvw-img">
            
            <p class="rvw-score">
             Title: Grief is the Thing with Feathers
                <br>
                Author: Max Porter
                   <br>     
            
                Score: <img src="ftlol-imgs/star-icon.png"alt="a star shaped icon in gold">
            </p>
                    
                  
          <!-- Trigger/Open The Modal -->
            <button id="myBtn6" class="btn-six">Read review</button>

            <!-- The Modal -->
            <div id="myModal" class="modal">

            <!-- Modal content -->
            <div class="modal-content">
            <span class="close">&times;</span>
                
                        
                 <h1>Grief is the Thing with Feathers</h1>
                        <p>
                        
 
                    </p>
                </div>

</div> 
                
                    
                </div>
                
        <!--REVIEW BOX SIX END -->


<style>
header {
  background-color: hsl(180, 90%, 35%);
  color: #FFFFFF;
}

nav {
  background-color: hsl (180, 80%, 25%);

}

h1 {
  text-indent: 10px;
  padding-top: 10px;
}

nav ul {
  margin: 0px;
  padding: 5px 0px 5px 30px;
}

nav li {
  display: inline;
  margin-right: 20px;
}

a {
  text-decoration: none;
  color: inherit;
}
</style>

<header>
<h1>Cooking with FCC!</h1>
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Classes</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>
</header>

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36.

Challenge: Adjust the Tone of a Color

Link to the challenge: