My code below opens a random website from the array but to stop going on the same website is there a way to delete it once it has been visited. Heres my attempt.
<button onclick="randomLink()";>Click here to go somewhere else!</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script type="text/javascript"> var randomLink = function () { var links = new Array(); links[1] = "http://google.com"; links[2]="http://bing.com"; var max = (links.length) var randomNumber = Math.floor(Math.random()*max); var link = links[randomNumber]; links.splice(randomNumber,1); $('iframe').attr('src', link); } </script> <iframe src="" name="iframe_a" ></iframe>
linksoutside of the function. You're deleting an item usingsplicebut then putting it back when you run the function again.links[0]key and you can have problems. It's better if you don't define the key, it will be asigned automatically by javascriptMath.floor(Math.random()*max)Can give 2 and will work incorrectly