How to multiply element values in classes?

Tell me how to multiply element values in classes? There is code in the middle of the page:
the <div>
<div class="title-price">Consultation </div> 
<span class="belrub">50</span> 
<span class="valusd"></span> 

<div class="title-price">Extras. services</div> 
<span class="belrub">110</span> 
<span class="valusd"></span> 
</div>

And there is code in the footer:
<span id="nulvalusd">15</span>

How to multiply the values in <span class="belrub">the value in <span id="nulvalusd">

And display the result in <span class="valusd">?

Please tell me.
April 3rd 20 at 18:24
1 answer
April 3rd 20 at 18:26
const composition = [...document.querySelectorAll(".belrub")]
 .map(e => +e.textContent)
 .reduce((a, b) => a * b);

document.querySelector(".valusd").textContent = composition;


UPD: after I read the question again, and decided that he needs.belrub times #nulvalusd:

const nulvalusd = +document.querySelector("#nulvalusd").textContent;

document.querySelectorAll(".belrub")
 .forEach(e => e.nextElementSibling.textContent = Math.round(+e.textContent.replace(/\s/, ") * nulvalusd));
And it will <span id="nulvalusd">15</span> to hang? - Tamara commented on April 3rd 20 at 18:29
@Tamara, I've updated the answer about 2 minutes ago, reconsider. - willa_Wisoky commented on April 3rd 20 at 18:32
It worked. Only have two requests, it can be if <span class="belrub"> is the number with a space (for example, 12 020), it is also considered to be, and now vday "NaN".
And second, in the <span class="valusd"> out the numbers are not whole numbers, they can be rounded to integers? - Tamara commented on April 3rd 20 at 18:35
@Tamara, just today, the action "Write code for free", updated the answer. - willa_Wisoky commented on April 3rd 20 at 18:38
No, I do exactly this solution will not work. So as to be multiplied more than once...
Here this structure is actually:
<span class="belrub">50</span> 
<span class="valusd"></span> 
<span class="valrub"></span> 
<span class="valeur"></span>

I just thought then by analogy to other currencies to distribute... - Tamara commented on April 3rd 20 at 18:41
@Tamara, Oh. Further itself. - willa_Wisoky commented on April 3rd 20 at 18:44
@willa_Wisoky, ungrateful thing )) - Scotty_Blanda commented on April 3rd 20 at 18:47
@Scotty_Blanda, yeah) - willa_Wisoky commented on April 3rd 20 at 18:50

Find more questions by tags JavaScript