Recently began learning Javascript on CodeAcademy and throughout the tutorials they use console.log(). However I heard I need to use .innerHTML instead when I'm just printing to a document so to practice this I wrote a small array and I want to write text using if/else statments with it. Sorry if my code is wrong, I'm pretty new to this but can someone explain how to implement the .innerHTML to this code?
Thanks in advance! (left the html in to show full layout).
function mylist(myArray) {
var backPack = [
gear = [
'compass',
'rope',
'tent',
],
food = [
'granola',
'oats',
'fruit',
],
clothes = [
'shirt',
'pants',
'underwear',
]
];
if (backPack.clothes !== 'socks') {
document.getElementById('display').innerHTML = "don't froget your socks!";
}else{
document.getElementById('display').innerHTML = "All your clothes are here!";
};
};
function check(){
document.getElementById('display').innerHTML = mylist();
}
<p id='display'></p>
innerHTMLlooks fine. The only problem I see is the if statement is comparing an arraybackPack.clothesto a stringsocks. You would need to check if the array containssocksinsteadbackPack.clothesis not valid syntax either:backPackis anarrayandclothesis an element of an array, not a property of it.