Forum Discussion
Can I prevent "NaN" from appearing in numerical entry?
Is there a way to do this? Am using conditions to handle which numbers ARE allowed and to display an error if invalid numbers are entered. But can't get it to stop letters etc from being entered/processed.
Hopefully I'm having a Friday moment and missing something simple
- Amanda-GunningCommunity Member
Hi there
I would like to add up a couple of numbers in Storyline 3. I thought I could use the number entry field to do this? The number goes in fine but when I try to add the value that was entered to a variable to add up a score, I get the NaN issue.
Is there a simple way around this yet? I am really suprised Storyline can't add a number(s) to a variable. Maybe I am missing something here?
I have tried the following workarounds:
1. setting the value of the total variable to 0 when the timeline starts.
2. changing the state of a tick/check image if the correct number is entered to normal.
3. using a drop down question but I have several of the same numbers including 0 to select.None of these work. I don't quite get how to apply the javascript so haven't tried that. Any explanation on how to add that would be helpful. e.g. do you just add the script and replace inH1 = numericentry1 variable?
Many thanks for any help with this.
Amanda
- MichaelHinzeCommunity Member
It would be easier to help, if you can share your .story file (or the one slide) here.
- Amanda-GunningCommunity Member
- SarahLyon-b2d06Community Member
I have successfully built out a calculation slide that works well when previewed. I have duplicated the slide in the same scene with the hopes of changing the scenario users will work through. Before making any changes to the duplicate slide I tested it and it's getting the the "NaN" error. Why would something work fine then when I duplicate it no longer work? I have read through the responses above and have not been able to fix the issue.
- KenFliegerCommunity Member
NAN is 'Not A Number' error in JavaScript. If you are not using custom JavaScript code then it bares down to extremely bad coding on the developer's side. The developer has to trap any strings, Infinity numbers and spaces or any other value the user may enter that is not a number value. Sloppy code writing.
- SarahLyon-b2d06Community Member
I didn't use any Javascript (I'm new to Storyline) and simply used the the programing within Storyline to assign variables and so on. I used this tutorial to build it. https://community.articulate.com/articles/setting-variables-to-perform-a-calculation-in-articulate-storyline
- BeccaLevanCommunity Member
Hi Sarah!
Any chance you could share your file? If folx can see what you have going in your project, it'll be easier to pinpoint what's going on and make suggestions!
- KevinMcGrathCommunity Member
Found this old thread when trying to solve the same issue in JavaScript. Thought I'd post here in case anyone else needs this solution:
a = a || 0
adding || 0 tell JS that if there's errors on the left side (e.g. NaN) then return a value of 0.
Thanks for sharing the solution that worked for you in this thread, Kevin! I'm sure it will be helpful to other community members that come across this post.
Have a great day, and happy developing! ✨