$(document).ready(function() {
var text = $('#text').text();
var word_array = text.split(' ');
// blank array to store result
var word_count = {};
// lets count the words
for ( var x in word_array ) {
// make the word lowercase
var word = word_array[x].toLowerCase();
// we are only interested in words with 3 or more characters
if ( word.length >= 3 ) {
if ( typeof word_count[word] != 'undefined' ) {
// if the word exists in the array, lets increase its count
word_count[word] += 2;
} else {
// if the word doesn't exist, lets set its initial count
word_count[word] = 2;
}
} // end if statement for word.length
} // end for look
// output the result to the cloud div
for ( var y in word_count ) {
$('#cloud').append('<div class="tag" style="font-size: '+ word_count[y] +'px;">' + y + '</div>');
}
});