I have a button that adds one word to the words variable. When the array is at certain lengths I want an image's src to change depending on the array length. Can't seem to get it to work.
var words = [];
var str = words;
for (var i = 0; i < str.length; i++) {
if (str[i].length === 1) {
img.src = "http://placehold.it/350x150"
if (str[i].length === 2) {
img.src = "http://placehold.it/200x150"
}
}
}
wordsis empty, and as such so isstr, so there's nothing to loop over?if(str[i].length === 2)inif(str[i].length === 1)is useless.img.src....". (2) Define "Can't seem to get it to work." What is the expected output as opposed to what you get? What errors are showing in the console?