Javascript question

Nov 17, 2013

I'm a newbie javascript programmer (learned all I know about it from Code Academy) although I've been programming in other languages for years. I figured out how to run a javascript from a trigger but I can seem to find out how to display the results. I've tried console.log and return but I can't get it to work. Can anyone help?

Here's my code:

//This script compares two different fixtures and shows how much it costs to operate them based on the wattage of the fixtures, how many hours they will be used every year, the cost of electricity, and the energy efficiency ratio (EER) of the HVAC.//

var newFixtureWatts = prompt("How many watts is the new fixture?")

var btu1 = 3.41214*newFixtureWatts

var tonsHvac1 = btu1/12000

var newFixtureHours = prompt("Estimate the number of hours per year the lights are on.")

var electCost = prompt("How much do you pay for electricity per kilowatt-hour?")

var eer = prompt("What is the energy efficiency ratio (EER) of the AC unit?")

var annCost1AC = (tonsHvac1*12000*newFixtureHours*electCost/1000)

var annCost1elect = (newFixtureWatts*newFixtureHours*electCost/1000)

return("The annual cost of running the AC with the new fixture is "+annCost1AC)

return("The annual cost of electricity to run the new fixture is "+annCost1elect)

var oldFixtureWatts = prompt("How many watts is the old fixture?")

var btu2 = 3.41214*oldFixtureWatts

var tonsHvac2 = btu2/12000

var annCost2AC = (tonsHvac2*12000*newFixtureHours*electCost/1000)

var annCost2elect = (oldFixtureWatts*newFixtureHours*electCost/1000)

return("The annual cost of running the AC with the old fixture is "+annCost2AC)

return("The annual cost of electricity to run the old fixture is "+annCost2elect)

prompt("Is your cost "+annCost2AC)

3 Replies
Michael Hinze

Hi Richard, I changed your script slightly (replaced the 'return' statements with 'document.write' statements, added; at the of each line) and now the script seems to work, see here. Obviously the formatting is ugly and I'm not sure how exactly you want to use this script (end the returned values) within Storyline. But the 'raw' script now works.

I wonder though why you would want to use a javascript for these calculations, from what I saw (I have no clue about the actual subject matter), you should be able to do this with triggers in Storyline. Hope that helps.

Richard Cadena

Wow, thank you Michael. That's what I was looking for.

I started writing this b/c I wanted an iPad app but after I wrote the script I read that javascript won't run from Articulate Storyline on an iPad. But I wanted to see how it would work on a desktop. I didn't think about just using triggers. I'm still a bit new to Storyline, but I'll give that a try. Thank you very much for your help.

This discussion is closed. You can start a new discussion or contact Articulate Support.