How to assigning more than 1 variable to a list


I’m having trouble figuring out how to assign more than 1 variable in the OnEvent. In the code below, the Wrong[0] is ONLY assigning number 0 in the handler, being Wrong1. I need to figure out how to put all 3 variables there, instead of just one. Thanks!

var Wrong = ["wrong1", "wrong2", "wrong3"];
onEvent("correct1", "click", function( ) {
onEvent(Wrong[0], "click", function( ) {

You are literally adding the onEvent only on the first element of the list, if you want you can simply loop over the list and add the event on each one.

Hope it helps :sparkles:

What exactly do you mean? I’m quite bad at this haha

I am not really sure about the language or technology you are using, but onEvent looks like a callback of sort.

You can loop over your items and add your events, each language has a way to iterate over a collection and “do something”.
For example a “for” loop in JavaScript looks like:

for(let i = 0; i < Wrong.length; i++) {
  onEvent(Wrong[i] ...)

Meaning that on each iteration i will change accessing a different value of your array.

Hope this better help :sparkles:

1 Like

Thank youu, got this workin :smiley:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.