40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
var timesClicked = 0;
|
|
function clickCount() {
|
|
timesClicked++;
|
|
if (timesClicked == 1) {
|
|
document.getElementById("theButton").innerHTML = "You've clicked me 1 time.";
|
|
} else {
|
|
document.getElementById("theButton").innerHTML = "You've clicked me " + timesClicked + " times.";
|
|
}
|
|
}
|
|
function main() {
|
|
// Clear output paragraph
|
|
document.getElementById("jsOutput").innerHTML = "";
|
|
var array = new Array(10);
|
|
|
|
for (let i = 0; i < array.length; ++i) {
|
|
let temp = parseInt(Math.random() * 100) + " array index: " + i;
|
|
array[i] = temp;
|
|
console.log(i);
|
|
}
|
|
|
|
for (let i = 0; i < array.length; ++i) {
|
|
for (let j = 1; j < array.length; ++j) {
|
|
let compare1 = array[i].slice(0, array[i].indexOf(" "));
|
|
let compare2 = array[j].slice(0, array[j].indexOf(" "));
|
|
console.log(compare1 + " " + compare2);
|
|
if (compare1 >= compare2) {
|
|
array[i] = array.splice(j, 1, array[i])[0];
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < array.length; ++i) {
|
|
document.getElementById("jsOutput").innerHTML += (array[i] + "</br>");
|
|
console.log(array[i]);
|
|
console.log(typeof(array[i]));
|
|
}
|
|
document.getElementById("jsOutput").innerHTML += ("JavaScript is an absolutely bizarre language.");
|
|
clickCount();
|
|
}
|