Hi. I'm new to javascript and something doesn't seem to be functioning right.
What I'm trying to make is a website that will spit out a movie (from an array) when clicking on a button.
In the picture you can see the website, as well as the javascript (top) and the html (bottom).
Is there something wrong with the javascript or did I not link it correctly to the button? Or do I need to give the website somewhere to display the movie name, like a text box?
Thanks
>>163785
first of all, inline JS like that is looked down upon
>onclick="pickMovie()"
second, all the function does is create a variable (randomValue) and define it, nowhere does it display it
third, you are not properly quoting the items in your array. Array items must be quoted with either single or double quotes:
> ' '
> " "
it looks like you are using a comma to start the quote
fourth, do not add a comma after the final item in an array, it has a chance to cause major issues in some browsers.
I have made a JS Fiddle that works properly, please note the changes made to the HTML as well (adding IDs and another P element to write the return value inside of)
https://jsfiddle.net/jaketr00/8xzsk6sd/1/
>>163785
1. Open it in your browser and open the console (F12), that'll show you errors.
2. Your Movies array is messed up, each string value should be enclosed in single quotation marks, separated by one comma. Like: var Movies = ['Castle in the Sky', 'Grave of the Fireflies', 'My Neighbor Totoro'];
3. Yes, you have to display your randomValue somewhere somehow, else it's just another variable like Movies. Try this: alert(randomValue);
>>163806
>German programs change the first quotation mark
I recommend using Brackets by Adobe, its made for web code.
http://brackets.io/
>>163811
I use sublime text, and it seems to work fairly well.
The problem I had was that I kept the list in a regular text program, simply to store it somewhere.
Thanks though.