2

I am trying to define the src in eval() but not working !! the eval line is not working. This is google console taking the error. The hyperlink is not working. enter image description here TypeError

<!doctype html>
<html lang="en"> 
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <script>
        var num = 1
        img1 = new Image()
        img1.src= "images/slide1.jpg"
        img2 = new Image()
        img2.src= "images/slide2.jpg"
        img3 = new Image()
        img3.src= "images/slide3.jpg"

        function slideShow(){
            num = num + 1
            if(num == 4){
                num = 1
            }
        document.slide.src = eval("img" + num + ".src")//having problem in this line
        }
    </script>
</head>
<body>
    <div class="slider">
        <img src="images/slide1.jpg" alt="">
        <a href="javascript:slideShow();">Click here for next image</a>
    </div>

</body>
</html>
Jency
  • 328
  • 1
  • 11

0 Answers0