html - JavaScript wouldn't display results of code -
i tried creating simple javascript file based on adaption of source code mdn.
my javascript code (loughshore_clubs.js) follows
<!-- var club = “ballinderry” ; function clubtype(name){ if (name == “ardboe”){ return name ; } else{ return “i'm not “+ name + “.”; } } var clubs {myclub: clubtype(“ardboe”), club2: clubtype(club), club3: clubtype(“moortown”)} console.log(clubs.myclub); //ardboe console.log(clubs.club2); //ballinderry console.log(clubs.club3); //moortown /-->
and html source (test.html) is
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title></title> <meta name="generator" content="libreoffice 4.2.4.2 (linux)"> <meta name="created" content="20150514;0"> <meta name="changed" content="20150514;211357234273120"> <style type="text/css"> <!-- @page { margin: 2cm } p { margin-bottom: 0.25cm; color: #000000; line-height: 120% } a:link { so-language: en-us } --> </style> </head> <body> <script src="scripts/loughshore_clubs.js" /> </body> </html>
what's matter? 1 thing realise should avoid saving html files using libreoffice , stick bluefish. (which have on mac o/s x yosemite)
remove first , last lines of script. html comment tags make no sense in .js
file.
then replace each of ”
characters proper "
.
you're missing =
between clubs
, {
here: var clubs {myclub:...
after these changes should have:
var club = "ballinderry"; function clubtype(name){ if (name == "ardboe") { return name; } else { return "i'm not " + name + "."; } } var clubs = { myclub: clubtype("ardboe"), club2: clubtype(club), club3: clubtype("moortown") }; console.log(clubs.myclub); //ardboe console.log(clubs.club2); //ballinderry console.log(clubs.club3); //moortown
Comments
Post a Comment