JavaScript to show current date will NOT work!

Can someone please explain to me what I am doing wrong?  I will attach the story file.  Slide 1.5 is where I want the current date to show.  I used the Storyline tutorial http://www.articulate.com/support/storyline/javascript-best-practices-and-examples and followed it perfectly.  When I publish my module and test it, the date does not appear whatsoever.  I have tried different browsers.  Can someone please tell me what I did wrong so I can learn from this?  Thanks!

5 Replies
Jackson Hamner

Your current script

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var dateString=month + "/" + day + "/" + year
var player = GetPlayer();
player.SetVar("SystemDate",dateString);

 

It should be:

var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var dateString=month + "/" + day + "/" + year;
var player = GetPlayer();
player.SetVar("SystemDate",dateString);

 

You need to add semicolons to the end of every command.

 Also for your page you should have %SystemDate% somewhere on there

Michael Hinze

@Stefanie: The issue is not with the date script, it's the script on the Success layer of the Results slide. If I remove this script, publish, upload and run, then the date script works. See a quick test here with the faulty script removed: http://dev.keypointlearn.com/xcl73_SL2/JSDate/V2/story.html 

Steve Flowers

Yep - that script is breaking it. Using the JavaScript console is really helpful when tracking down strange issues. Breaking up the lines and adding each line to your variable might help. I didn't do a character count but that many characters in the body of a mailto: might cause problems with some mail clients.

var email="MDLZpolicy@arifleet.ca";
var subject="Mondelez Canada Tool of Trade Motor Vehicle Policy ACKNOWLEDGEMENT";
var body_start="<p>I acknowledge receipt of the following; Mondelez Canada Tool of Trade Motor Vehicle Policy effective date January 1, 2015</p>";
body_start+="<p>I acknowledge that I have read and understand the Mondelez Canada Inc. Tool of Trade Motor Vehicle Policy and I agree to act in accordance with this policy and requirements as a condition of my employment by Mondelez Canada. I understand that if I have questions or concerns at any time about the TOT policy, I will consult my immediate supervisor, my supervisor's manager, or the Manager of Sales Policies and Fleet.</p>:";
body_start+="<p>I further acknowledge and understand the following:";
body_start+="<ul type="circle">";

Stefanie Gettemans

Thank you all so much!  I removed the script on the Results slide, and the Date works fine.... I haven't used Javascript in a very long time, so this is why I am so rusty :)

So, does this mean, I won't be able to execute the email I want to?  The email executed fine before.  But, adding this date variable in made everything all hokey.