I want to add js code to the html.
Hi @amejl172!
Are you referring to adding a script tag to your html page and writing js in there?
In Atom for example I have html code and JS code. I want to link the JS to the html, so I wirte the code on the JS file, and only use the html for browser and size.
You can create an external js script and link it with your html page.
You can call it index.js.
Here is an example from one of my projects.
I have <script></script>
with my source to file, but, In the js
I have this code var LC = document.getElementById('LineChart');
I donāt know if it links, because nothing happens in the browser.
Are you doing something with that variable?
Right now it looks like you are just getting an id but not doing anything with it.
I have this code for it
LC = new Chart("LineChart", { type: 'line', data: data, options: options });
Iām trying to make a line chart, so I can see it in the browser but, I donāt know how to link it to html.
Well you can open up the console in dev tools and check for error messages.
I have this error
ReferenceError: Chart is not defined
It is probably referring to this.
In the error messages, it will tell you which line in the js script the error is.
LC = new Chart(āLineChartā, {
^
they say this, but I have var LC
in code already.
Where did you define Chart though?
I donāt have defined it.
Well thatās what the error message says.
If I define it I need to make it to a variable. But I were expecting it to be a command, because Iām new to programming.
The computer is looking for something called Chart and it canāt find it so you need to define it.
How do you define it?
I know when defining itās var
, but this one I donāt understand why to make it a variable.
Well you can create a new object called linechart and assign this to it.
But I am not entirely sure why you want to assign this object to this:
document.getElementById('LineChart').
What are you trying to accomplish here?
When I watch YouTube and looked at CHART.JS, this is what I thought I had to do.
I donāt understand what the code does exactly.
I will read again.
Itās I think to get html code <canvas id = "LineChart", height = 400px, width = 1832px></canvas>
I am not familiar with that library but I would go through documentation.