I am trying to make this work but I am clearly doing something wrong which I can't figure out:
function template(data){
var contentString =
'<div id="content">'+
'<div class="left">'+
"<div class='icon'><img src='assets/image/cloudy.png' /></div>"+
'</div>'+
'<div class="right">'+
'<p class="temp">'+data.currently.temperature+'</p>'+
'<p class="summary">'+data.daily.summary+'</p>'+
'</div>'+
'<div class="day_wrapper">'+
for(i = 0; i < data.daily.data.length; i++){
'<div class="day"><p>'+data.daily.data[i].temperatureMax+'</p></div>'+
}
'</div>';
return contentString;
}
Error: Uncaught SyntaxError: Unexpected token for
How can I fix this?
How would I add a 'last' class to the last paragraph in the loop?
contentString +=inside your for loop. Remove the+just before the loop and addcontentString +=before your lastdiv.forloop , continue inside it, then continue after it. I also would strongly advice the use of a templating framework like mustache.js for example...