What is wrong with this javascript code?
<script type="text/javascript">
<!–Hide from old browsers
var today = new Date()
var dayofweek = today.toLocaleString()
dayLocate = dayofweek.indexOf(" ")
weekDay = dayofweek.substring(0, datelocate+1)
newDay = dayofweek.substring(dayLocate)
dateLocate = newDay.indexOf(" ")
monthDate = newDay.substring(0, dateLocate+1)
yearLocate = dayofweek.IndexOf("2006")
year = dayofweek.substr(yearLocate, 4)
var fairDate = new Date("August 17, 2006")
var daysToGo = fairDate.getTime()-today.getTime()
var daysToFair = Math.ceil(daysToGo/(1000*60*60*24))
document.write("<h3 style=’margin-left:10%’>Today is "+weekday+" "+monthdate+" "+year+". We ")
document.write("have "+daysToFair+" days until the start of the fair on August 17, 2006!")
document.write("<br /> See the finest in local crafts, atys, plants and flowers,m animals, and agricultural technology. ")
document.write("Join us for rides, musical entertainment, and the best local cussine.</h3>")
//–>
</script>
The problem is it wont show up the text please help
Tagged with: agricultural technology • animals • br • ceil • crafts • cussine • dayofweek • document write • flowers • h3 • Hide • indexof • lt • math • musical entertainment • new date • newday • plants • quot • script type • text javascript • var
Filed under: Tech News
Like this post? Subscribe to my RSS feed and get loads more!
Do you know any Javascript? There are tons of errors here… no semicolons, some variables are declared and others aren’t, capitalization is all screwed up, your variables are out of order, etc.
Here is some code that renders some text (but this could be rewritten with MUCH better code):
<script type="text/javascript" charset="utf-8">
var today = new Date();
var dayofweek = today.toLocaleString();
var dayLocate = dayofweek.indexOf(" ");
var weekDay = dayofweek.substring(0, dateLocate+1);
var newDay = dayofweek.substring(dayLocate);
var dateLocate = newDay.indexOf(" ");
var monthDate = newDay.substring(0, dateLocate+1);
var yearLocate = dayofweek.indexOf("2006");
var year = dayofweek.substr(yearLocate, 4);
var fairDate = new Date("August 17, 2006");
var daysToGo = fairDate.getTime()-today.getTime();
var daysToFair = Math.ceil(daysToGo/(1000*60*60*24));
document.write("<h3 style=’margin-left:10%’>Today is "+weekDay+" "+monthDate+" "+year+". We ");
document.write("have "+daysToFair+" days until the start of the fair on August 17, 2006!");
document.write("See the finest in local crafts, atys, plants and flowers,m animals, and agricultural technology. ");
document.write("Join us for rides, musical entertainment, and the best local cussine.</h3>");
</script>