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
43 Replies
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! ✨
- RobSkeetCommunity Member
Hey Storyline Peeps, I built a Sum of Ratios calculator for a client. it's proprietary so I can't share it but wondered if there has been any non JS solutions for this. essentially, the user plugs in lab results and it determines the sum of ratios. It all works great until someone goes back into a field and deletes the entry or hits backspace. then all the calculations giv NaN because the deleted default is not an actual 0. if you overwrite it with a zero, itt all works again but this is not very user friendly. BTW, I tried to add the JS that was suggested above and it just ignored it. (Yes, even when published to Review) any new ideas? is this something that Articulate is working on? it's been 13 years since the first complaint.
- NedimCommunity Member
You may try below. But it all depends on your current setup.
var num = getVar("NumericEntry"); if (num === "" || isNaN(num)) { setVar("NumericEntry", 0); }
- 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.
- 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!
- 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 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.
- 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
- DivyaPeruguCommunity Member
- ChrisWalshCommunity Member
@Divya,
Your requirement will be pretty complex because you will require three separate boolean IsNaN variables to separately test each of the numeric values Year, Month and Day, and then display an alternative Age value if any one of them is a NAN value.
This might be easier to do in JavaScript where theNumber.isNaN()
function is readily available. I could help but you would need to provide:- The variable names and types of the DOB and Age fields
- How you are getting the Year, Month and Day from the "Date of Birth" field
- What your triggers currently look like.
Thanks Miquel! Never too late to pop in and assist as it could certainly help someone in the future :)
Welcome to E-Learning Heroes by the way ☺️
- MiquelCapCommunity Member
Thanks! :)
- MiquelCapCommunity Member
Hey Simon, I had the same problem and I tried to leave with a 0, this way, in a group it can calculate the sum of the fields.
I see that this conversation is from 5 years ago, so I hope you had solved XD, but if can be useful for other people I did this:
IF( NOT( {string} > 0) , 0 , {string})- BobbyBlake-541aCommunity Member
Hi Miquel,
Could you provide a little more insight on how to plug this into a course?
For example, the variable I'm trying to keep from being NaN is labeled "NumericEntry1"
Hi Michelle,
Thanks for coming to share your need for this change and feature within Storyline, and I'm sorry it's caused you difficulty as you build your courses. Our team does keep an eye on the ELH forums and that feature request form, and uses all that information when looking at ways to update Storyline. Each feature idea is tracked thru that form and as our team looks at creating them, they focus on how many customers are impacted, what other workarounds or solutions are available, and the overall impact on the product (if it's going to change anything else about the way it works). All that information is used to determine priority and it seems this set up hasn't risen to that highest level yet. I hope that offers a bit more insight into the process and please continue to keep us in the loop on what you'd like to see in Storyline or our other products!
Related Content
- 11 months ago
- 28 days ago
- 8 months ago
- 2 months ago