-1

I have the following code (Using https://www.w3schools.com/js/ Because i don't know how else to test it)

<p id="demo"></p>

<script>

var a,b,c,d,e,text = "",x,y;
a = 25
b = Math.floor( a / 8 )
c = a - ( b * 8)
if (c == 0)
c = 8;
d = Math.ceil ( a / 8 )
e = 8
for (y = 1; y <= d; y++) {
    for (x = 1; x <= e; x++) {
    text += "<br>" + x + "," + y;
    }
}
document.getElementById("demo").innerHTML = text;
</script>

I was hoping that when var a (user input) was set to any number between 1 and 96 it would give all the coordinates from 1,1 to that number of well (on a 96 well plate A1 to H12.

eg. var a = 25 would give 1,1 2,1 3,1 4,1 5,1 6,1 7,1 8,1 1,2 2,2 3,2 4,2 5,2 6,2 7,2 8,2 1,3 2,3 3,3 4,3 5,3 6,3 7,3 8,3 1,4 and stop. Instead it finishes off the rest of the column 2,4 3,4 4,4 5,4 6,4 7,4 8,4 and then stops.

How do I get it to stop in the right place??

Thank you

Rufus Long
  • 33
  • 2

1 Answers1

0

This should works, hope it helps!

var text = "", start = 8, end = 25;

for (var i = start; i < end; i++) {
    text += "<br>" + ((i % 8) + 1) + "," + (Math.floor(i / 8) + 1)
}

document.getElementById("demo").innerHTML = text;
<p id="demo"></p>
AngYC
  • 3,051
  • 6
  • 20