My codes work but I tend to put them in a loop …
<code>const titleSale1 = document.createElement("span");
const titleSale2 = document.createElement("span");
const titleSale3 = document.createElement("span");
const node1 = document.createTextNode("special sale");
const node2 = document.createTextNode("special sale");
const node3 = document.createTextNode("special sale");
titleSale1.appendChild(node1);
titleSale2.appendChild(node2);
titleSale3.appendChild(node3);
const element = document.querySelectorAll('.onsale');
element[0].appendChild(titleSale0);
element[1].appendChild(titleSale1);
element[2].appendChild(titleSale2);
</code>
<code>const titleSale1 = document.createElement("span");
const titleSale2 = document.createElement("span");
const titleSale3 = document.createElement("span");
const node1 = document.createTextNode("special sale");
const node2 = document.createTextNode("special sale");
const node3 = document.createTextNode("special sale");
titleSale1.appendChild(node1);
titleSale2.appendChild(node2);
titleSale3.appendChild(node3);
const element = document.querySelectorAll('.onsale');
element[0].appendChild(titleSale0);
element[1].appendChild(titleSale1);
element[2].appendChild(titleSale2);
</code>
const titleSale1 = document.createElement("span");
const titleSale2 = document.createElement("span");
const titleSale3 = document.createElement("span");
const node1 = document.createTextNode("special sale");
const node2 = document.createTextNode("special sale");
const node3 = document.createTextNode("special sale");
titleSale1.appendChild(node1);
titleSale2.appendChild(node2);
titleSale3.appendChild(node3);
const element = document.querySelectorAll('.onsale');
element[0].appendChild(titleSale0);
element[1].appendChild(titleSale1);
element[2].appendChild(titleSale2);
I want to make code less, more readable and for more variables
New contributor
md adineh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.