In this task, the objective is to compare two sets of ten randomly generated numbers using Javascript to determine whether they are greater than, less than, or equal to each other.
So far, I have the following code:
document.write("Comparing Numbers from Corresponding Lists: <br>");
var list1 = new Array();
for (var i = 0; i < 10; i++) {
list1[i] = Math.round(Math.random() * 100);
}
var list2 = new Array();
for (var i = 0; i < 10; i++) {
list2[i] = Math.round(Math.random() * 100);
}
if (list1 > list2) {
document.write(list1 + " is greater than " + list2);
} else if (list1 < list2) {
document.write(list1 + " is less than " + list2);
} else if (list1 == list2) {
document.write(list1 + " is equal to " + list2);
}
Currently, it displays the following output:
Comparing Numbers from Corresponding Lists:
15, 4, 30, 39, 46, 8, 91, 85, 64, 17 is less than 97, 78, 32, 50, 60, 36, 42, 6, 12, 80
However, I would like the output to be in two columns resembling a table with two columns and ten rows. A classmate suggested incorporating the if/else if statement within a for () loop, but I am unsure about what parameters should go inside the loop. For the first two statements, I considered something along these lines:
for (var list1 = 0, list2 = 0; list1.length, list2.length; ...) {
I apologize if this sounds too simple or obvious, but I am struggling to figure it out. Thank you in advance for any assistance.