Articulate Storyline: In need of help, JavaScript, displaying text based on keypad input

Jun 07, 2021

Hi,

I am new to JavaScripting, but i have build a keypad with help from discussions on this site. When pressing the buttons the input is added to a variable X.

What i would like to do now is, when pressing enter on the keypad a certain text according to the number pressed should be displayed i variable Y.

Example: Pressing 158 on the keypad this should be displayed in X, then when pressing enter, Banana should be displayed in Y.

I have tried with several statements, case, if else and array. but i can't get it to work.

Any inputs is much appreciated, remember i am new to scripting.

 

THX. Jesper

3 Replies
Walt Hamilton

Go to w3schools.com. They have a way for you to try your script, without having to publish your SL project. Copy the script, and paste it into their "Try It" function. place this line after the first line in your script: 

         alert("Works to this point");

When the script gets to this line, it will show a dialog box. When JS encounters an error, it stops, without showing an error message. If the dialog box shows, you know that the script works to that point. Move the alert line one line down in the script and run it, until when you run it, the box doesn't show up. The error in the script is immediately above the alert line. Then you can use the tutorials to figure out the problem.

If all the script lines function, and you don't get the response you want, it is not a JS error, but a logic problem.