Skip to content

Instantly share code, notes, and snippets.

@mentix02
Created December 24, 2017 10:14
Show Gist options
  • Save mentix02/31fe88e0d665eee47cada93f67d8406d to your computer and use it in GitHub Desktop.
Save mentix02/31fe88e0d665eee47cada93f67d8406d to your computer and use it in GitHub Desktop.
Append all even and odd numbers from 0 to 100 into separate rows and columns
<!DOCTYPE html>
<html>
<head>
<title>Odd Even</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<table border="1" id="evenOddTable">
<tr>
<td>Odd</td>
<td>Even</td>
</tr>
</table>
<script>
even = [];
odd = [];
for (var i=0; i<=100; i++){
if (i % 2 == 0) {
even.push(i);
}
else{
odd.push(i);
}
}
for (var j=0; j<=odd.length-1; j++){
$('#evenOddTable tr:last').after('<tr><td>' + odd[j] + '</td><td>' + even[j] + '</td></tr>');
}
$('#evenOddTable tr:last').after('<tr><td></td><td>100</td></tr>')
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment