Problem with run my js code

<p class="parr">This is paragraph 5</p>

<p>This is paragraph 6</p>

<p class="p2Cl">This is paragraph 7</p>

<p class="p2Cl">This is paragraph 8</p>

<p class="parr">This is paragraph 9</p>

<button onclick="fn1()">Click on</button>


  <script src="script.js"></script>

function fn1(){

  var element=document.getElementsByClassName("parr");

  if( x=0,x<element.length,x++){

    element[ x ].style.color="red";



Can someone explain my why ny code not working the right?
Even if i use ; or , still no working :confused: What I doing wrong?

what should your code do? what is it happening instead?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This is an if statement:

if (x === 3) {
   // do something

This is a for loop:

for (let x = 0; x < elements.length; x++) {
  // do something
1 Like

Yes, thanks so much.

I absolutly not understadn what U want for me. U want help me or what …?

Yes, but to help you understand why a piece of code is not working you should at least explain what it should do

I think it was absolutly clearly in my question, or no?
How ur reaction can help ppl who ask for help where u just say that ( if u want help, write u code like monkey here).
Sorry but I hope you understand me, if person ask for help, and everything is show on window, so why I will replace it on any code agains?

I can’t read your mind, I don’t know what you want your code to do.
Learning to describe problems is an important part of learning how to code.

Sorry,but maybe just read code? jsdisco solved this problem so fast. where I shared my html code with few

and down is my javascript function, where if I try click on I was want run my code, but it was dont working. So where is problem ?
So, and if like u say U cant read my mind, dont react on my post, it isnt so hard, dont react, thanks, I see many ppl just do same like you if person ask for helping, but not solved problem. But If u have experince of that, so solved problem if u know,and if no so be silence, and if U solve it after that maybe explain other think in you main what u mean about correct any code . But I hope, it was absolutly clearly and easly reading,and question was help solve problem that I dont know why function not working, so ?

You say your code doesn’t work, but I don’t know how it doesn’t work if you don’t say so

Just saying “My code doesn’t work help” means the person you are asking for help will have to read carefully all your code to try to understand what you want it to do, and then try to understand how it is not doing that

if you explain at least what the code should do, you are making it easier to help you, instead of giving all the work to the person helping

Yes, maybe I could have done it anyway spending a couple of minutes, but if you are asking for help should make it as easy as possible for the person helping you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.