Basic JavaScript Learning


(Joao Ribeiro) #1

Hi Guys,

I am trying to do my first JavaScript trial. I am trying to do something very simple as to include a function in HTML’s head to listen to a button’s click, add that count to a variable and console.log this variable.
Just to see the start of interaction, but I can’t make it work.
Any help will be much appreciated.
Thanks,
Joao


(Rick) #2

It’s really hard guessing what you are trying to do without a project file… :thinking:


(Loves Hype) #3

Here is a general guide to start Javascript and CSS

After that the forum has plenty of examples and project files with code to load and examine using Javascript. Just search for the topic you are interested in.

Then you will find all the hypeDocument specific API functions in the documentation here:
https://tumult.com/hype/documentation/3.0/#javascript

Hope this helps


(Joao Ribeiro) #4

Hi Rick,

It is a very simple function, just to understand how javascript and hype integrate with eachother.

https://we.tl/t-3lGOOKGBVV
The javascript button should count the number of clicks.

Cheers,

Joao


(Joao Ribeiro) #5

Hi Max,
I am taking a course in Javascript, the thing is I don’t quite understand hoe they integrate with each other.

I am new to this, so be patient, maybe in the future things will get easier.

Thanks,

Joao


(Hans-Gerd Claßen) #6

if you want to place code to the headsection and have access to hypes API:

https://tumult.com/hype/documentation/3.0/#invoking-api-from-outside-oftumult-hype


(Joao Ribeiro) #7

Hi Hans, I read it but didn’t quite understood it. I have to export the document in order to know the document’s name then go back to hype to call it from hype’s html head?
I just would like to see it work once to understand how to call it and interact with it.

Cheers,

Joao


(Hans-Gerd Claßen) #8

read a bit deeper … about Hypes Events and then following an example : https://tumult.com/hype/documentation/3.0/#events


#9

Joao,

you can attach hype projects directly to your reply using the upload button in the toolbar at the top of your message.

You had your code in a function called myCallback which was in the HeadHTML. However, in the Actions inspector, you had set a click to run untitledFunction() which is empty.

You need to move only the code inside myCallback (not the whole myCallback function) into untitledFunction(). Once you do that, it will work provided you add quotes around your ID like this: ("Contador"). If you don’t add quotes, the code will look for a variable named Contador which, of course, does not exist. IDs are strings, not variables.

If I were you, I would look at the documentation that the others have linked to because you have to learn a little bit more about the basics to understand what you’re trying to do here.


(Joao Ribeiro) #10

GOT IT!
Thanks!