Cut And Paste Code For Lesson 5


Simple Delay Says "Hello World:"

Simple Delay Says "Hello World" after one second:

<!DOCTYPE html>
<html>
<body>
<script>

var myVar = setInterval(myTimer ,1000);
function myTimer() {
 document.write("Hello World")
}

</script>
</body>
</html>


Draw A Rectangle With Multi Colored Lines:

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

ctx.beginPath();
ctx.moveTo(20, 20);
ctx.lineTo(20, 100);
ctx.strokeStyle = "blue";
ctx.stroke();

ctx.beginPath();
ctx.moveTo(20, 100);
ctx.lineTo(70, 100);
ctx.strokeStyle = "black";
ctx.stroke();

ctx.beginPath();
ctx.moveTo(70, 100);
ctx.lineTo(70, 20);
ctx.strokeStyle = "red";
ctx.stroke();

ctx.beginPath();
ctx.moveTo(70, 20);
ctx.lineTo(20, 20);
ctx.strokeStyle = "green";
ctx.stroke();

</script>  
</body>
</html>