Forum Discussion

BrentMiller-1e7's avatar
BrentMiller-1e7
Community Member
27 days ago

Javascript not executing correctly

I've been using articulate to build out a tool for people create comprehensive school safety plans. Part of the tool (scene 5 in the attached articulate file) has slide that shows people where strategies they've checked off on a previous slide fall based on two dimensions. 

On the first slide of the scene (5.1), users would check off all strategies they are using and hit the submit button. That triggers a layer where true/false variables for each checkbox are adjusted if the box is checked before moving on. The final results slide (5.4-matrix) is intended to show a matrix of selected strategies organized by two different sets of variables. I've been using javascript code to put those items into arrays.

I've been running into some problems with this approach. When I preview the entire story, the code does not appear to run at all. When I preview just the scene, the code does run but marks all variables as true regardless of what was checked off. I'm hoping someone can take a look at the file and provide some guidance on how to resolve this.

Thanks!

 

  • I have attached a modified file with an updated script on 5.4. Start with this and see what is or is not working. If you have more questions, you can ask for more help here.

    I didn't try to analyze your scene or guess what data should be present, but I did fix some errors in your script so it at least functioned.

    Mainly, when comparing values in JS you need to use a == or === operator, not a =. The = is for assigning a value. See https://www.w3schools.com/js/js_comparisons.asp

    You also forgot to read in the SchoolSecurityGuards variable from SL.

    Some suggestions to help with coding:

    1. Press F12 while viewing your published project in your browser. Click on the Console tab and look there for script errors.
    2. Copy the text of your script from SL and paste it into https://jshint.com/. This will give you insight into possible errors that you have in the structure of your code.
    3. You might want to put 'var' before each line that reads in your SL variables (as you did when defining the arrays)