How to check the validation of js files or html files including js?

Joined
Nov 23, 2019
Messages
70
Reaction score
1
I returned back (from DOM to objects and would see one very simple sample in real application but that is not running as I expect or understand.

see that sample here:


<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> javascript simple sample</title>
<script>
var hotel = {
name: 'park',
rooms: 77,
booked: 34,
salinta: function() {
return this.rooms - this.booked;
}
};
var elName = document.getElementById('hotelName');
elName.textContent = hotel.name;

var elRooms = document.getElementById('rooms');
elRooms.textContent = hotel.salinta();
</script>
</head>
<body>
<div id="hotelName"></div>
<div id="rooms"></div>
</body>
</html>

but more than the sample,I think I should be able to check the validation of such files (or only js files). when I check this html form W3C validation,it returns no error,but it is not running. :(
 
Last edited:
Joined
Nov 27, 2019
Messages
163
Reaction score
28
I have never found a validation for JS that I trusted. I write pieces of code and verify myself - then add them to the large script. As for your code - It is doing what it the code says and working correctly. What did you want it to do?

Three things:
First place your JS after your HTML code, but before the </body> tag. That allows the HTML to execute faster and get the web site up and running for the user.

Next, I use alerts to see where I am and what variables are doing. Modern day is to use the console. Your choice.

Lastly, I changed the amount of rooms booked - ran - code and got the correct number of rooms available. GOOD!
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> javascript simple sample</title>

</head>
<body>
<div id="hotelName"></div>
<div id="rooms"></div>

<script>
var hotel = {
  name: 'park',
  rooms: 77,
  booked: 34,
  salinta: function() {
  return this.rooms - this.booked;
  }
}

var elName = document.getElementById('hotelName');
elName.textContent = hotel.name;

hotel.booked = 41;
var elRooms = document.getElementById('rooms');
elRooms.textContent = hotel.salinta();
</script>
</body>
</html>

If your still here look at this site:
http://xahlee.info/js/js_textContent_innerHTML_innerText_nodeValue.html
 
Joined
Nov 23, 2019
Messages
70
Reaction score
1
I have never found a validation for JS that I trusted. I write pieces of code and verify myself - then add them to the large script. As for your code - It is doing what it the code says and working correctly. What did you want it to do?

Three things:
First place your JS after your HTML code, but before the </body> tag. That allows the HTML to execute faster and get the web site up and running for the user.

Next, I use alerts to see where I am and what variables are doing. Modern day is to use the console. Your choice.

Lastly, I changed the amount of rooms booked - ran - code and got the correct number of rooms available. GOOD!
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> javascript simple sample</title>

</head>
<body>
<div id="hotelName"></div>
<div id="rooms"></div>

<script>
var hotel = {
  name: 'park',
  rooms: 77,
  booked: 34,
  salinta: function() {
  return this.rooms - this.booked;
  }
}

var elName = document.getElementById('hotelName');
elName.textContent = hotel.name;

hotel.booked = 41;
var elRooms = document.getElementById('rooms');
elRooms.textContent = hotel.salinta();
</script>
</body>
</html>

If your still here look at this site:
http://xahlee.info/js/js_textContent_innerHTML_innerText_nodeValue.html

hi sunfighter ,welcome once again.
both the thing I was thinking is correct (but not as exactly as I was thinking ) and it is really running now as you said.

mm,I was only trying to make exercises but failed unfortunately.

and how can we make better exercises under the information you provided here.
as you know browser is neglecting all of javascript codes when it comes across any failure
how to pass this matter?

thanks
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
and how can we make better exercises under the information you provided here.
as you know browser is neglecting all of javascript codes when it comes across any failure
how to pass this matter?

When I'm trying to help someone that has a long complicated JS script I first pretty the file so the indentions are nice, then collapse the sections add alert("DONE to my specs"); at the end of the file (a macro) and start commenting sections out til the code runs. Last one is in error so I place it in a separate file and study it.
 
Joined
Nov 23, 2019
Messages
70
Reaction score
1
No it is not.
so,normally you are not Xah Lee
ok.

And I use innerHTML. My mentor hates that - says it's wrong as it makes the page reload and wastes time, but I have a macro setup and just continue using it

I also think it would be wrong (but not for you,currently for me or someone who are not as good as required in js) :) it may cause xxs as you know. I learnt something about it but do not think that the consistence of the magic, would be only not allowing special characters (required characters) in all inclusive areas in html document.

simpy or with more understandable form,I think the scope of xxs should be wider.

When I'm trying to help someone that has a long complicated JS script I first pretty the file so the indentions are nice, then collapse the sections add alert("DONE to my specs"); at the end of the file (a macro) and start commenting sections out til the code runs. Last one is in error so I place it in a separate file and study it.

I see.
that lso shows you enjoy your study area.
I appreciate it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top