[ANSWERED] Trying to better understand JavaScript in Izzyv4
-
Hi all
I've been working through a simple javascript thing I want to achieve, but no experience of writing code other than html about 20 years ago...
I have 4 values going into the JS actor, and I want those values to be ordered highest to lowest, then spat out at the other side as 4 outputs - highest at the top, lowest at the bottom.
Utilising chat GPT I have a stable JS actor that closes and takes 4 random shuffled numbers in, but don't really know what i'm doing, and the values are not coming out. I read both the help in the actor, and the isadora page for help.
I tend to find I can learn better by dissecting something that is working. Is someone around here able to simply build this script so I can import it and see where I was going wrong?
It's driving me mad! I would normally achieve the task using isadoras actors, but the method around it gets quite complicated, considering the general simplicity of the outcome. It utilises a lot of comparators, max value, remapping, etc.
The intended outcome is that we can create with the students a realtime score board with names. I need to understand how complex this is before I set it as a task for them - knowing full well I can't actually do it myself!
This would give me good insight into simple java script utilisation for when I am teaching interactivity at work.
Many thanks in advance!
Steve
-
Array Sort - Example in Isadora
This example allows you to do a quick highest to lowest. You can simple change the inputs and outputs to scale it with more items or less if needed.
-
@skuven said:
good insight into simple java script
take a look at Juriaans script in the Javascript actor.
The two key points are:
One, how he is creating an array by looping through the input arguments (also an array) and creating arrayToBeSorted by using push() to add each value to the end of the array.JavaScript Array push() MethodTwo, how he is using the very powerful (and slightly confusing to learn) sort() function, to apply a sort to the array. The method for the application of the sort() is defined after the calling of sort() as a simple function that returns a-b. Really to understand that part you need to read up on the function. JavaScript Array sort() Method
-
@dusx
Thanks Dusx for adding that and making sure that we also learn the methods that were being used.The only thing that I have to add is that 'arguments' or basically the 'array' that gets fed into our main function is not of type 'array', or it gives an error in your Windows > Show Monitor view when you try to sort the arguments array.
That is why it was required to make a new array that is basically an mirror of the arguments array, that way we could actually execute the built-in-methods of an array like 'sort'