<h1>heelo</h1>
<script type ="text/javascript">
//this all should redirect but does not
alert('You are being redirected to random website')
var responses = ["https://www.google.com", "https://www.youtube.com"]
var rand = responses[Math.floor(Math.random() * responses.length)];
window.location.replace(`${rand}`)
}
Asked
Active
Viewed 361 times
-5

showdev
- 28,454
- 37
- 55
- 73

Dhairya Gupta
- 1
- 1
-
3That code looks incomplete. Which errors are you getting? – showdev Dec 12 '17 at 22:01
-
Need to close that script tag and remove the extra `}` at end. use your browser console to check errors – charlietfl Dec 12 '17 at 22:04
-
you probably want `window.location.href = rand` – Get Off My Lawn Dec 12 '17 at 22:10
1 Answers
1
I changed the way the JavaScript variable is provided to replace()
.
It's simply rand
rather than `${rand}`
.
I also removed the unmatched closing }
and added the matching closing </script>
.
<h1>heelo</h1>
<script type ="text/javascript">
alert('You are being redirected to random website')
var responses = ["https://www.google.com", "https://www.youtube.com"]
var rand = responses[Math.floor(Math.random() * responses.length)];
window.location.replace(rand)
</script>

showdev
- 28,454
- 37
- 55
- 73

Meenakshi Khandelwal
- 173
- 1
- 2
- 14