<html>
<head>
<script>
window.onload = function () {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.lineWidth = 2;
context.strokeStyle = "black";
context.font = "30pt Calibri";
context.fillText('Pythagorean Theorem', 230, 40);
//Draw right triangle
context.moveTo(300, 50);
context.lineTo(300, 150);
context.lineTo(350, 150);
context.lineTo(300, 50);
context.stroke();
context.fillText('a', 270, 110);
context.fillText('b', 310, 180);
context.fillText('c', 340, 130);
context.lineWidth = 1;
context.moveTo(300, 140);
context.lineTo(310, 140);
context.lineTo(310, 150);
context.stroke();
context.font = "14pt Calibri";
context.fillText('In any right triangle with legs a and b and hypotenuse c:', 80, 220);
context.fillText('a + b = c ', 220, 260);
context.font = "10pt Calibri";
context.fillText('2 2 2', 228, 254);
context.font = "14pt Calibri";
do {
var ranA = Math.floor((Math.random() * 200) + 1);
var ranB = Math.floor((Math.random() * 200) + 1);
var coverOne = Math.floor((Math.random() * 3) + 1);
hypoNum = Math.sqrt((ranA * ranA) + (ranB * ranB));
} while (hypoNum > Math.floor(hypoNum));
context.fillText('Here we have provided two of the', 200, 300);
context.fillText('three values and you will need', 200, 320);
context.fillText('to solve for the unknown.', 200, 340);
context.fillText('a = ' + ranA, 230, 370);
context.fillText('b = ' + ranB, 230, 390);
context.fillText('c = ' + hypoNum, 230, 410);
context.fillText('ANSWER = ', 230, 430);
context.fillText('Click on the box', 230, 450);
context.fillText('to see the unknown value.', 230, 470);
context.fillText('Side Hidden: ' + coverOne, 230, 490);
// Adding the below draw to see if it gets to this.
// context.fillRect(230, 370, 100, 50);
// It doesn't complete this, so something is missing in the above script
// The purpose of the below conditional statement is to cover over one of the three answers
// with a rectangle.
if (coverOne == 1) {
context.fillRect(230, 370, 100, 50);
}
else if (coverOne == 2) {
context.fillRect(230, 390, 100, 50);
}
else if (coverOne == 3) {
context.fillRect(230, 410, 100, 50);
}
}
</script>
</head>
<body>
<div align="center">
<canvas id="myCanvas" width="800" height="800" style="border:1px solid black;">
</canvas>
</div>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |