Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

How to fix an array in JavaScript

$
0
0

I'm currently testing some coding for a website I'm hoping to publish in the future which will generate a line of random text when you press a button. I've followed some instructions online on how to write the code however upon testing the button no information is coming through and on opening the javascript file I receive the message:

Script:xxxxx
Line: 4
Char: 1
Error: Expected ']'
Code: 800A03EF
Source: Microsoft JScript compilation error

Here is the relevant javascript:

var Message = [
'message 1''message 2''message 3''message 4''message 5''message 6''message 7''message 8'
]
function MessageDisplay() {
    var randNum = Math.floor(Math.random() * (Message.length));
    document.getElementById('MessageDisplay').innerHTML = Message[randNum];
}

What I'm hoping to see when a button is clicked on the page, is a message saying something like "Message 3". However, at the moment I'm getting nothing


Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>