Skip to content

Instantly share code, notes, and snippets.

@mackenco
Created March 12, 2017 23:52
Show Gist options
  • Save mackenco/fd88136f91dcb98d71a7e97cc482763b to your computer and use it in GitHub Desktop.
Save mackenco/fd88136f91dcb98d71a7e97cc482763b to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=fd88136f91dcb98d71a7e97cc482763b
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<canvas id="myCanvas"></canvas>
</body>
</html>
/* lines 2 - 14 set up functions to draw shapes
* you don't need to adjust them
*/
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
function rectangle(length) {
ctx.rect(20,20,length*2,length);
ctx.stroke();
}
function circle(radius) {
ctx.beginPath();
ctx.arc(100, 75, radius, 0, 2*Math.PI);
ctx.stroke();
}
// DO NOW STARTS HERE
function draw() {
if (shape === 'rectanle') {
rectangle();
} else {
}
}
// these two should work
draw("rectangle", 10);
draw("circle", 25);
// these two should tell the user they did something wrong
draw("banana", 5);
draw("circle");
canvas {
height: 400px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment