Unless you have a variable named red with a string value of “red”, the line above is not going to do what you hope.
Do you have an existing element in your HTML with an id=“myArray”?
It would help if you posted a link to your code using Codepen.io, jsFiddle.net or similar site. Then we can see your full code and any changes you make to it.
code
i would like to change the font color to red when the array appears using the this line of code document.getElementById("myWishes").innerHTML = wishes;
i was trying to do it in this way:
Yes, but if you are going to use common styling on elements, it would be better to create a class selector in CSS add the class to the element. If you have predefined elements in your HTML, you could do the following instead:
HTML
<p>Be careful with what you wish my friend</p>
<p id="myWishes" class="wishes"></p>
<button onclick="myWishes()">Show me my wishes</button>
CSS
.wishes {
color: red;
background:blue;
}
JS
function myWishes() {
var wishes = ["soda", "pasta", "tv", "pizza"];
document.getElementById("myWishes").innerHTML = wishes;
}