I've written the following:
var pages=["[www.facebook.com] Facebook is cool. ","[www.bbc.co.uk] British broadcasting corporation. "];
function findScoreC2(s){
var scores=[];
var percentageScores=[];
var contentsArray=[];
s=s.toLowerCase();
for(i=0;i<pages.length; i++){
contentsArray=pages[i].substring(pages[i].indexOf("]")+1,pages[i].lastIndexOf(" "));
var lowerCaseContents=(pages[i].substring(pages[i].indexOf("]")+1,pages[i].lastIndexOf(" "))).toLowerCase();
scores[i] =(lowerCaseContents.split(s)).length-1
};
percentageScores=(scores[i] / contentsArray[i].length) * 100;
var finalArray=[];
for(i=0;i<percentageScores.length;i++){
finalArray.push("{score:"+percentageScores[i]+",index:"+i+"}")
};
alert(finalArray);
}
findScoreC2("facebook");
however, alert(finalArray)
alerts to nothing (ie an alert box comes up but it says nothing) when it should alert "{score:33,index:0},{score:0,index:1}"
.
Could anyone enlighten me as to why this might be?
Thanks very much