Skip to content

Instantly share code, notes, and snippets.

@Bijesse
Created December 8, 2016 20:37
Show Gist options
  • Save Bijesse/d62b5f338fb996c474466d23481e9633 to your computer and use it in GitHub Desktop.
Save Bijesse/d62b5f338fb996c474466d23481e9633 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=d62b5f338fb996c474466d23481e9633
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<meta charset="utf-8" />
<script>
</script>
<title>JS-Grid We Do</title>
</head>
<body>
<h2>Fun on a grid</h2>
<div class="intro">You get a function:
<div class="code">
setColor(row, column, color);
</div>
For a given row and column (both numbered from 0), it colors the corresponding cell.
<br>
<strong>Directions:</strong> type
<span class="code">
setColor(2, 0, "purple");
</span>
on line 6 of JavaScript
</div>
<table id="t">
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
</body>
</html>
{"enabledLibraries":["jquery"]}
function setColor(row, col, color) {
var cell = $('#t')[0].rows[row].cells[col];
cell.style.backgroundColor = color;
}
// Write your code below this line
#t {
border-collapse: collapse;
}
#t td {
border: 1px solid blue;
width: 1em;
height: 1em;
}
.intro {
font-family: arial;
line-height: 1.5em;
margin-bottom: 1em;
}
.code {
color: green;
font-family: monospace;
font-weight: bold;
}
div.code {
border: 1px solid green;
padding: 3px;
padding-left: 1em;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment