Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
A string that shows the generated number

I want to add a string that shows the current amount of pictures generated from the code, like "number of pictures:"

<h1 id="number-of-p">Antall bilder:</h1>
<input id="add-img-btn" type="button" value="Legg til bilde" />
<div id="output-div"></div>

<script>
  var addImgBtn = document.getElementById("add-img-btn");
  var outputDiv = document.getElementById("output-div");
  var addNumberOfP = document.getElementById("number-of-p");

  function addRandomNumber() {
    const rnd = (addNumberOfP = Math.floor(Math.random() * 100 + 1));
    let html = [];
    for (let i = 0; i <= rnd; i++) {}
    numberOfP.innerHTML = html.join("");
  }

  function addRandomImg() {
    const rnd = (addImgBtn = Math.floor(Math.random() * 100 + 1));
    let html = [];
    for (let i = 0; i <= rnd; i++) {
      html.push('<img src="img/mann.jpg"/>');
    }
    outputDiv.innerHTML = html.join("");
  }

  addImgBtn.onclick = addRandomImg;
  addNumberOfP.onclick = addRandomNumber;
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here this will work!

var addImgBtn = document.getElementById("add-img-btn");
var outputDiv = document.getElementById("output-div");
var addNumberOfP = document.getElementById("number-of-p");

function addRandomImg() {
  const rnd = (addImgBtn = Math.floor(Math.random() * 100 + 1));
  let html = [];
  for (let i = 0; i <= rnd; i++) {
    html.push('<img src="https://randomuser.me/api/portraits/men/4.jpg"/>');
  }
  outputDiv.innerHTML = html.join("");
  addNumberOfP.innerHTML = `Antall bilder: ${(rnd + 1)}`;
}

addImgBtn.onclick = addRandomImg;
<h1 id="number-of-p">Antall bilder:</h1>
<input id="add-img-btn" type="button" value="Legg til bilde" />
<div id="output-div"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!