How to Include JavaScript in Our HTML | JavaScript Tutorial | Learn JavaScript | For Beginners. In this JavaScript tutorial you will learn how to include JavaScript code inside a website, both directly in the HTML and as a separate JavaScript file.
➤ GET ACCESS TO MY LESSON MATERIAL HERE!
First of all, thank you for all the support you have given me!
I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful 🙂
Material for this lesson: LINK
Original source
29 responses to “4: How to Include JavaScript in Our HTML | JavaScript Tutorial | Learn JavaScript | For Beginners”
Thx man. You really helped me out.
When accessing your .js file from the folder with the <script src>
Does the positioning rule still apply as before?
This video deserve also subtitle
so i can't use sublime text 3 edit
#1 go to for coding
How to make a popup on a webpage using javascript?
In second option, the content didn't show after all, but the first one works, help
Great video man this help me alot!
Amazing !!
How do I run this in a browser? Did i miss a video?
You're adding JavaScript into the <body> tag for teaching purposes, I get that. I'm using the MEAN stack in vs code, each component has it's own TS file which accepts JavaScript. Should I be adding my JavaScript to my TS file?
why are small youtubers the best at teaching
i never supported any youtuber before, but you are an exception your content is extraordinary, keep up pls.
Ii love you If I could I would give you a 100 bucks ❤️😭🚀
the shortcuts dont work for me
Hello mmtuts developer I spent whole day and half (36hours) after through over in your 20video of Javascript DOM by fighting with this issues of connecting my html form with my javascript codes but till now is not working…. right now the stuff i tried to fix then working on html form are button and paragraph (results) but there are two inputs which are remain unworking please check for me my codes if you could help me to fix this issue
My project link on codepen.io
https://codepen.io/key-joshua/pen/XQGJdz
Please communicate me through
My Email: k.joshua855@gmail.com
Or
Share us with more explanation of how you fixed this challenge on your next lesson
Proud to see you
HTML # # # # # # # # # # # # # # #
<code><!DOCTYPE html>
<html>
<body>
<div class="header">
<h1>Scale Balancing</h1>
</div>
<div class="input-groups">
<div class="input-group">
<label>Weights</label>
<!– <br> –>
<input type="text" name="weight" id="weights" />
<!– <br><br> –>
<label>Weights_Lists</label>
<!– <br> –>
<input type="text" name="weights_list" id="weights_lists" />
<!– <br><br> –>
<button id="balance" class="btns">Balance</button>
<br><br><br><br>
<p id="results" >Results….</p>
</div>
</div>
<script src="js/script.js"></script>
</body>
</html></code>
CSS # # # # # # # # # # # # # # # # #
<code>
*
{
margin: 0px;
padding: 0px;
}
.header{
width: 30%;
margin: 50px auto 0px;
color: white;
background: #423107;
text-align: center;
border: 1px solid #B0C4DE;
border-bottom: none;;
border-radius: 10px 10px 0px 0px;
padding: 20px;
}
form{
width: 20.5%;
margin: 0px auto;
padding: 20px;
border: 1px solid #B0C4DE;
border-radius: 0px 0px 10px 10px;
}
.input-group{
margin: 15px 0px 15px 0px;
}
.input-groups{
width: 29.5%;
margin: 0px auto;
padding: 20px;
border: 1px solid #B0C4DE;
border-radius: 0px 0px 10px 10px;
}
.input-group label{
color: #423107;
display: block;
text-align: left;
margin: 3px;
}
.input-group input{
height: 30px;
width: 93%;
padding: 5px 14px;
font-size: 16px;
border-radius: 5px;
border: 1px solid gray;
}
.btns{
float: left;
padding: 10px;
font-size: 15px;
color: white;
background: #4c390c;
/*border: none;*/
border-radius: 5px;
}
</code>
JAVASCRIPT # # # # # # # # # # # # #
<code><script>
const btn= document.getElementById("balance");
const message = document.getElementById("results");
const right = 2;
//const right = document.getElementById("weights").value;
const left = 5;
//const left = document.getElementById("weights_lists").value;
const weights_list = [1,3,2,40,7];
//let weights_list = document.getElementById('weights_list').value.split(',');
function ScaleBalancing() {
for (x = 0; x <weights_list.length; x++ )
{
if ( right == left )
{
message.innerHTML=" Already This Scale Balanced ";
}
else if ( right+weights_list[x]===left
||
right===left+weights_list[x])
{
message.innerHTML=' You Will Use ' + '' + weights_list[x] +' To Balance This Scale ';
}
for ( y=x+1; y<weights_list.length; y++)
{
if
(
right+weights_list[x]+weights_list[y] === left
||
left + weights_list[x] + weights_list[y] === right
||
right +weights_list [x] === left +weights_list [y]
||
left + weights_list[x] === right + weights_list[y]
)
{
message.innerHTML= ' You Use ' +'' + weights_list[x] + ',' + weights_list[y]+' To Balance This Scale ';
}
}
}
return'Scale Imbalanced !! There is no Weights into weights _list To Balance This Scale ';
}
btn.addEventListener('click', function(){
console.log(ScaleBalancing());
})
</script></code>
what! where is the subtitle. Subtitle open please. 🙁
Me!: When Learning HTML And CSS And Java Script For The First Time!: —–> 0%
Now!: +5%!.
i cant run the code what should i do? any advise!!!!!!
Hello beginner here, so this is the first video I am doing one of your tutorials on and the first with atom. I did everything in the video checking it over several times. When I try to get the "This is some content" on the webpage. It will go with HTML, but not JS and I get the message "Failed to load resource: net::ERR_FILE_NOT_FOUND" should I get some kind of package? Or if anyone could give me a point in the right direction
Hmm. I followed everything exactly, but i had to omit the first js, and only put src="main.js", otherwise it wouldn't work.
its working even if i placed the script on head
199 likes and 106K subs this video should get more views and likes
Why notdo like this?
window.onload = startup;
function startup () {
document.body.innerHTML = "This is some content";
}
this way your script will wait for the page to load before it runs
My favorite channel on YouTube…. Seriously😍😍😍😍😍😍😍😍👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻
What if i wanted to just make apps for android, could javascript work?
When I refresh the page after i entered the main.js source i get an error that says "Not allowed to load local resource" any idea why?
Hello Sir, Tab sign isn't showing in my Atom version, I think it only shows for JavaScript but not for HTML? Can you please help me?
Thank you
lol, I watched this because I couldn't figure out why he needed 8:20 minutes to tell this. but it was the atom plug in the beginning 🙂