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

209
Views
How to print multilined array(passwise sorting) output in javascript?(on browser, not on console)

I have done this program to sort the array and print the result passwise. I have tried a lot but I am not getting what is wrong in my code. Can someone guide me what changes should I make in html/js to print the result passwise?

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<div class="screen-body-item">
<div class="app-form">
  <div class="app-form-group">
    <input type="text" class="app-form-control" placeholder="enter size" id="size">
    <input type="text" class="app-form-control" placeholder="enter element" id="ele">
    <input type="button" value="submit" class="app-form-button" onclick="mainfunc()">

<h3> Bubble sort</h3>
    <div class="app-form-group showdata" id="showData_bubble">
    </div>
    <div class="app-form-group showdata" id="passes_bubble">
    </div>
    <div class="app-form-group showdata" id="swaps_bubble">
    </div>

//javascrpt sorting function(I haven't mentioned input function here)
//mainfunc()
//bubble sort
    var noofpasses_bubble = 0, noofswaps_bubble = 0;
    for (let i = 0; i < size; i++) {
      noofpasses_bubble++;

      for (var j = 0; j < (size - i - 1); j++) {

        if (inputArray[j] > inputArray[j + 1]) {

          var temp = inputArray[j]
          inputArray[j] = inputArray[j + 1]
          inputArray[j + 1] = temp
          noofswaps_bubble++;
        }
        document.getElementById('showData_bubble').innerHTML = `Result after pass ${i+1} is ${inputArray}`
      
      }
        document.getElementById('passes_bubble').innerHTML = `Number of passes(b) are  

${noofpasses_bubble}document.getElementById('swaps_bubble').innerHTML =Number of swaps(b) are ${noofswaps_bubble}`

    }
about 4 years ago · Juan Pablo Isaza
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!