I tried adding HTML and JS together in the codepen but it wasn’t working.
Showed syntax errors: redeclaration of variables.
If possible,Do help me with that too.
So it will be easier for understanding if we have both codes on the same page.
Hello @Coder_In_Progress, for the html the part I think this should be enough
<body>
<section>
</section>
</body>
Then, in the don’t edit code below parts a variable called section is used without being declared. I suggest that you add once, at the top of your javascript code this line (which selects the <section> element in your html): const section = document.querySelector('section');
At this point, we still have the problem about variables being redeclared. Have a look at all the don’t edit code below parts: all of them declare variables para1 and para2 this comes from the fact that you grouped all three tests in one file. You should declare new variables for paragraphs that will come after para1 and para2 and to do so… you have to edit the don’t edit code below parts
Replace the second don’t edit code below part with this:
let para3 = document.createElement('p');
para3.textContent = 'Your finalResult is ${ finalResult }';
let para4 = document.createElement('p');
let finalNumberCheck = isNaN(finalNumber) === false ? 'finalNumber is a number type. Well done!' : 'Ooops! finalNumber is not a number.';
para4.textContent = finalNumberCheck;
section.appendChild(para3);
section.appendChild(para4);
And replace the third one with this:
let para5 = document.createElement('p');
let para6 = document.createElement('p');
let para7 = document.createElement('p');
let weightTest = weightComparison ? 'True — elephants weight less than mice!?' : 'False — of course an elephant is heavier than a mouse!';
let heightTest = heightComparison ? 'True — an ostrich is indeed taller than a duck!' : 'False — apparently a duck is taller than an ostrich!?';
let pwdTest = pwdMatch ? 'True — the passwords match.' : 'False — the passwords do not match; please check them';
para5.textContent = weightTest;
section.appendChild(para5);
para6.textContent = heightTest;
section.appendChild(para6);
para7.textContent = pwdTest;
section.appendChild(para7);
That’s the modification I added to your code pen and it worked just fine.