You just need to fix typos
function ShowJoke()
{
var Joke=[1, 2, 3, 4, 5, 6, 7];
var Pick = Math.floor(Math.random() * (Joke.length));
document.write(Joke[Pick]);
}
and actually call the function
ShowJoke();
EDIT:
Turns out op doesn't want to repeat the same joke, so we could do something like this:
function ShowJoke()
{
var RawJoke=[1, 2, 3, 4, 5, 6, 7];
var ToldJokes = localStorage.getItem("jokes");
if (ToldJokes) {
ToldJokes = JSON.parse(ToldJokes);
} else {
ToldJokes = [];
}
var Joke = [];
for (var i = 0; i < RawJoke.length; i++)
if (ToldJokes.indexOf(RawJoke[i]) === -1)
Joke.push(RawJoke[i]);
if (Joke.length === 0) {
ToldJokes = [];
Joke = RawJoke;
}
var Pick = Math.floor(Math.random() * (Joke.length));
ToldJokes.push(Joke[Pick]);
localStorage.setItem("jokes", JSON.stringify(ToldJokes));
document.write(Joke[Pick]);
}
source
share