Null output when printing result

Hi there

I use an authoring tool called storyline 3 which supports JavaScript. The storyline file starts with the following code in the back end…

Execute JS – when timelines starts on this slide

var objToday = new Date(),
weekday = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'),
dayOfWeek = weekday[objToday.getDay()],
domEnder = function() { var a = objToday; if (/1/.test(parseInt((a + "").charAt(0)))) return "th"; a = parseInt((a + "").charAt(1)); return 1 == a ? "st" : 2 == a ? "nd" : 3 == a ? "rd" : "th" }(),
dayOfMonth = today + ( objToday.getDate() < 10) ? '0' + objToday.getDate() + domEnder : objToday.getDate() + domEnder,
months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
curMonth = months[objToday.getMonth()],
curYear = objToday.getFullYear(),
curHour = objToday.getHours() > 12 ? objToday.getHours() - 12 : (objToday.getHours() < 10 ? "0" + objToday.getHours() : objToday.getHours()),
curMinute = objToday.getMinutes() < 10 ? "0" + objToday.getMinutes() : objToday.getMinutes(),
curSeconds = objToday.getSeconds() < 10 ? "0" + objToday.getSeconds() : objToday.getSeconds(),
curMeridiem = objToday.getHours() > 12 ? "PM" : "AM";
var today = curHour + ":" + curMinute + "." + curSeconds + curMeridiem + " " + dayOfWeek + " " + dayOfMonth + " of " + curMonth + ", " + curYear;
document.getElementsByTagName('h1')[0].textContent = today;

However, when I print out the result, I get a null result. What am I doing wrong?

Not sure what you mean by “when I print out the result, I get a null result”.
How are you trying to run this code?
What does your HTML file look like?
What are you expecting to see on the page when this code runs?

https://360.articulate.com/review/content/57978459-8b6f-4c75-8959-4e609709b792/review

If you run the link above,
Click Next
Rate the next three question 1-5 then hit next
Click Print/Save

You’ll be presented with a printable document. At the top I have a null result.

1st trigger - Execute JavaScript when user clicks on the next button

var objToday = new Date(),
weekday = new Array(‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’, ‘Saturday’),
dayOfWeek = weekday[objToday.getDay()],
domEnder = function() { var a = objToday; if (/1/.test(parseInt((a + “”).charAt(0)))) return “th”; a = parseInt((a + “”).charAt(1)); return 1 == a ? “st” : 2 == a ? “nd” : 3 == a ? “rd” : “th” }(),
dayOfMonth = today + ( objToday.getDate() < 10) ? ‘0’ + objToday.getDate() + domEnder : objToday.getDate() + domEnder,
months = new Array(‘January’, ‘February’, ‘March’, ‘April’, ‘May’, ‘June’, ‘July’, ‘August’, ‘September’, ‘October’, ‘November’, ‘December’),
curMonth = months[objToday.getMonth()],
curYear = objToday.getFullYear(),
curHour = objToday.getHours() > 12 ? objToday.getHours() - 12 : (objToday.getHours() < 10 ? “0” + objToday.getHours() : objToday.getHours()),
curMinute = objToday.getMinutes() < 10 ? “0” + objToday.getMinutes() : objToday.getMinutes(),
curSeconds = objToday.getSeconds() < 10 ? “0” + objToday.getSeconds() : objToday.getSeconds(),
curMeridiem = objToday.getHours() > 12 ? “PM” : “AM”;
var today = curHour + “:” + curMinute + “.” + curSeconds + curMeridiem + " " + dayOfWeek + " " + dayOfMonth + " of " + curMonth + ", " + curYear;
document.getElementsByTagName(‘h1’)[0].textContent = today;

YOU ANSWER THE QUESTIONS.

The JavaScript attached to the Print/Save button

var myWindow = window.open("",“Print”,“width=810,height=610,scrollbars=1,resizable=1”);
var player=GetPlayer();
var headline=player.GetVar(“Development - Communication, Oral and Written”);
var date=player.GetVar(“SystemDate”);
var usernotes=player.GetVar(“notes”);
var exercisenotes1=player.GetVar(“DevCommsDef”);
var exercisenotes2=player.GetVar(“DevCommsExp”);
var exercisenotes3=player.GetVar(“DevCommsEmp”);
var exercisenotes4=player.GetVar(“DevCommsClass”);
var exercisenotes5=player.GetVar(“DevCommsSport”);
var exercisenotes6=player.GetVar(“DevCommsVol”);
var exercisenotes7=player.GetVar(“DevCommsNote”);
var contents = “”
contents += “

Print Recommendation
”;
contents+="
"+headline+"
";
contents+="
"+date+"
";
contents+=“
Definition
”;
contents+="
"+exercisenotes1+"
";
contents+=“
Explanation
”;
contents+="
"+exercisenotes2+"
";
contents+=“
Employment
”;

And as you see from the results, I can get the value of DevCommsDef etc, barring the first line.

What have I done wrong?

I don’t really understand what this is supposed to do. What does the GetVar method do? Is SystemDate a variable? Where is it assigned a value?

It’s designed to capture the date from the computer your using at the time.

Well date is one of the variables that results in null and so is the variable headline. I know next to nothing about the Storyline 3 software. From what I gather from the quick search through some Storyline 3 documentation is the the getVar method will return the value of the argument passed to it. Unless you have a variable named “Development - Communication, Oral and Written”, headline will be null. Also, unless you have a variable named “SystemDate”, date will be null.

Also, when I look at the browser console, I see a message involving “notes”. I assume you have not defined a variable named notes for it to return a value other than null if you were to reference usernotes anywhere here.

UPDATE: “SystemDate” is not a valid variable unless you used:

var player = GetPlayer();
player.SetVar("SystemDate",today);

in the other section of code where you created the today variable.

You need to use the SetVar method in a similar way for the “usernotes” variable and more than likely need to do something like the following for headline.

player.SetVar("headlineText",“Development - Communication, Oral and Written”);