-
Fri 2021.05.28
'now, all I want is to be able to "see"(print) that value-position'
Place L11
analogRead(A5)
inside a small snippet, similarly to this example using an accelerometer:ref: ' I've only just pick up JS w/ Espruino and I'm kind of struggling'
Okay, @GeorgeM you did clarify indicating new to Espruino, does that include the interpreter language Javascript as well?
The understanding of 'undefined' needs to be revisited.
'that it's printing undefined because it calls for the print much faster than it takes the function to complete'
'(at least I'm pretty sure that's what's going on)'
The ninth bullet item down the list at:
http://www.espruino.com/FAQ
will take you to:
http://www.espruino.com/FAQ#when-i-type-a-command-why-does-espruino-print-undefined-Espruino follows the convention established at MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
See explanation below heading DescriptionOther useful resource:
Right, just so it's out the way... I've only just pick up JS w/ Espruino and I'm kind of struggling with a simple piece of code:
All I'm trying to do atm is to read a value from a POT(mimicking a future sensor) which then gets stored in an array depending on the two inputs which then would get the position in that array of the greatest value stored... now, all I want is to be able to "see"(print) that value-position, then store it under another const/ let and do something with it...
In Python this would be something simple like:
Now the printing issue is kind of solved in the sense that I can just print the return of that conditional:
But if I'm doing it from where I'm calling the function it's giving me "undefined"... now I get the fact that it's printing undefined because it calls for the print much faster than it takes the function to complete and output something out(at least I'm pretty sure that's what's going on)... but just as a test I've tried using a setTimeout on the print of about 3sec and I'm still getting undefined back which only confused me even more...