2021-04-28

Apr 28 In-Class Exercise Thread .

Please post solution solutions to the Apr 28 In-Class Exercise to this thread.

Best,

Chris

Please post solution solutions to the Apr 28 In-Class Exercise to this thread. Best, Chris

-- Apr 28 In-Class Exercise Thread

<!DOCTYPE html> <head> <title>Exercise</title> </head> <body> <script type="text/javascript"> function jump() { let elementStyle = document.getElementById("text").style; elementStyle.bottom = "0.5in"; elementStyle.color = "red"; setTimeout(function() {elementStyle.bottom = "0in"; elementStyle.color="black"}, 5000) } </script> <div onclick="jump()"> <p id="text" style="position: relative; font-size: 32px; color: black;">Jump!</p> </div> </body> </html>

<!DOCTYPE html> <head> <title>Exercise</title> </head> <body> <script type="text/javascript"> function jump() { let elementStyle = document.getElementById("text").style; elementStyle.bottom = "0.5in"; elementStyle.color = "red"; setTimeout(function() {elementStyle.bottom = "0in"; elementStyle.color="black"}, 5000) } </script> <div onclick="jump()"> <p id="text" style="position: relative; font-size: 32px; color: black;">Jump!</p> </div> </body> </html>

-- Apr 28 In-Class Exercise Thread

&lt;pre&gt;

&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;title&gt;Jump!&lt;/title&gt; &lt;script type=&quot;text/javascript&quot;&gt; function jump() { var jump = document.getElementById(&#039;jump&#039;); jump.style = &quot;top: 0.5in; color: red;&quot;; setTimeout(function () { var jump = document.getElementById(&#039;jump&#039;); jump.style = &quot;top: 1in; color: black;&quot;; }, 5000); } &lt;/script&gt; &lt;style&gt; #jump { position: absolute; top: 1in; font-size: 32px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div onclick=&quot;jump()&quot; id=&quot;jump&quot;&gt;Jump!&lt;/div&gt; &lt;/body&gt; &lt;/html&gt;

&lt;/pre&gt;

<pre> <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Jump!</title> <script type="text/javascript"> function jump() { var jump = document.getElementById('jump'); jump.style = "top: 0.5in; color: red;"; setTimeout(function () { var jump = document.getElementById('jump'); jump.style = "top: 1in; color: black;"; }, 5000); } </script> <style> #jump { position: absolute; top: 1in; font-size: 32px; } </style> </head> <body> <div onclick="jump()" id="jump">Jump!</div> </body> </html> </pre>

-- Apr 28 In-Class Exercise Thread

&lt;pre&gt; &lt;!doctype html&gt;&lt;html&gt; &lt;head&gt; &lt;title&gt; jumping text exercise &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;jumpText&quot; style=&quot;color:black;font-size:32px;position: absolute; left:1in; top: 2in&quot; onclick=&quot;move(&#039;0.5&#039;)&quot;&gt; Jump! &lt;div&gt; &lt;script&gt; function goBack(movement){ temp = document.getElementById(&quot;jumpText&quot;).style; temp.color= &quot;black&quot;; temp.top = movement + &quot;in&quot;; }//goBack

  function move(movement){
    temp = document.getElementById("jumpText").style;
    temp.color= "red";
    temp.top = movement + "in";

    setTimeout(function(){goBack(2);}, 5000);
  }//move
</script>

&lt;/body&gt; &lt;/html&gt; &lt;/pre&gt;

<pre> <!doctype html><html> <head> <title> jumping text exercise </title> </head> <body> <div id="jumpText" style="color:black;font-size:32px;position: absolute; left:1in; top: 2in" onclick="move('0.5')"> Jump! <div> <script> function goBack(movement){ temp = document.getElementById("jumpText").style; temp.color= "black"; temp.top = movement + "in"; }//goBack function move(movement){ temp = document.getElementById("jumpText").style; temp.color= "red"; temp.top = movement + "in"; setTimeout(function(){goBack(2);}, 5000); }//move </script> </body> </html> </pre>

-- Apr 28 In-Class Exercise Thread

&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;title&gt;Ajay Salh&lt;/title&gt; &lt;style&gt; div { font-size: 32px; padding: 1in 0.25in; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;jump&quot;&gt;Jump!&lt;/div&gt; &lt;script type=&quot;text/javascript&quot;&gt; document.getElementById(&quot;jump&quot;).onclick = function() { myStyle = document.getElementById(&quot;jump&quot;).style; myStyle.color=&quot;red&quot;; myStyle.padding = &quot;0.5in 0.25in&quot; setTimeout(revert, 5000); }

  function revert() {
    myStyle = document.getElementById("jump").style;
    myStyle.color="black";
    myStyle.padding = "1in 0.25in"
  }
</script>

&lt;/body&gt; &lt;/html&gt;

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ajay Salh</title> <style> div { font-size: 32px; padding: 1in 0.25in; } </style> </head> <body> <div id="jump">Jump!</div> <script type="text/javascript"> document.getElementById("jump").onclick = function() { myStyle = document.getElementById("jump").style; myStyle.color="red"; myStyle.padding = "0.5in 0.25in" setTimeout(revert, 5000); } function revert() { myStyle = document.getElementById("jump").style; myStyle.color="black"; myStyle.padding = "1in 0.25in" } </script> </body> </html>

-- Apr 28 In-Class Exercise Thread

&lt;pre&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;div id=&quot;jump&quot; onclick=&quot;jump()&quot; style=&quot;font-size:32px;position:relative;top: 0.5in&quot;&gt;Jump!&lt;/div&gt; &lt;script&gt; var jumper = document.getElementById(&quot;jump&quot;); function jump() { jumper.style.cssText = &quot;font-size:32px;color:red;position:relative;&quot;; setTimeout(jumpEnd, 5000); }

function jumpEnd() { jumper.style.cssText = &quot;font-size:32px;position:relative;top: 0.5in&quot;; } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; &lt;/pre&gt;

<pre> <!DOCTYPE html> <html> <head></head> <body> <div id="jump" onclick="jump()" style="font-size:32px;position:relative;top: 0.5in">Jump!</div> <script> var jumper = document.getElementById("jump"); function jump() { jumper.style.cssText = "font-size:32px;color:red;position:relative;"; setTimeout(jumpEnd, 5000); } function jumpEnd() { jumper.style.cssText = "font-size:32px;position:relative;top: 0.5in"; } </script> </body> </html> </pre>

-- Apr 28 In-Class Exercise Thread

&lt;nowiki&gt;&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt; &lt;title&gt;Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;jump&quot; style=&quot;color: black; font-size: 32px; position: absolute; top: 5in;&quot; onclick=&quot;jump();&quot; &gt; Jump! &lt;/div&gt; &lt;script type=&quot;text/javascript&quot;&gt; function jump(){ let height = 4.5; let jumpStyle = document.getElementById(&quot;jump&quot;).style; jumpStyle.color = &quot;red&quot;; jumpStyle.top = height + &quot;in&quot;; let interval = setInterval(() =&gt; { height -= 0.5; jumpStyle.top = height + &quot;in&quot;; }, 500) let timeout = setTimeout(() =&gt; { clearInterval(interval); jumpStyle.top = &quot;5in&quot;; jumpStyle.color = &quot;black&quot;; }, 5000); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt;&lt;/nowiki&gt;

(Edited: 2021-04-28)
<nowiki><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="jump" style="color: black; font-size: 32px; position: absolute; top: 5in;" onclick="jump();" > Jump! </div> <script type="text/javascript"> function jump(){ let height = 4.5; let jumpStyle = document.getElementById("jump").style; jumpStyle.color = "red"; jumpStyle.top = height + "in"; let interval = setInterval(() => { height -= 0.5; jumpStyle.top = height + "in"; }, 500) let timeout = setTimeout(() => { clearInterval(interval); jumpStyle.top = "5in"; jumpStyle.color = "black"; }, 5000); } </script> </body> </html></nowiki>

-- Apr 28 In-Class Exercise Thread

&lt;nowiki&gt; &lt;!DOCTYPE html&gt; &lt;head&gt; &lt;title&gt;April 28&lt;/title&gt; &lt;/head&gt; &lt;body&gt;

&lt;div id=&quot;jumpDiv&quot; style=&quot;font-size:32pt; color: black;&quot; onclick=&quot;jumpUp()&quot;&gt;Jump&lt;/div&gt; &lt;script&gt; function jumpUp(){ var jumpStyle = document.getElementById(&quot;jumpDiv&quot;).style jumpStyle.top = &quot;0.5in&quot; jumpStyle.color = &quot;red&quot;; var timer = setTimeout(() =&gt; { jumpStyle.top = &quot;0in&quot; jumpStyle.color = &quot;black&quot;; }, 5000);

}

&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; &lt;/nowiki&gt;

<nowiki> <!DOCTYPE html> <head> <title>April 28</title> </head> <body> <div id="jumpDiv" style="font-size:32pt; color: black;" onclick="jumpUp()">Jump</div> <script> function jumpUp(){ var jumpStyle = document.getElementById("jumpDiv").style jumpStyle.top = "0.5in" jumpStyle.color = "red"; var timer = setTimeout(() => { jumpStyle.top = "0in" jumpStyle.color = "black"; }, 5000); } </script> </body> </html> </nowiki>

-- Apr 28 In-Class Exercise Thread

&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;

&lt;head&gt; &lt;meta charset=&quot;utf-8&quot;&gt; &lt;title&gt;In-class exercise&lt;/title&gt; &lt;/head&gt;

&lt;body&gt; &lt;div id=&quot;jump&quot; style=&quot;color: black; font-size: 32pt; position: relative;&quot; onclick=&#039;jump()&#039;&gt;Jump!&lt;/div&gt;

<script>
    function jump()
    {
        var myStyle = document.getElementById("jump").style;
        myStyle.bottom = "0.5in";
        myStyle.color = "red";
        setInterval(function() {myStyle.bottom = "0in"; myStyle.color="black"}, 5000);
    }
</script>

&lt;/body&gt; &lt;/html&gt;

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>In-class exercise</title> </head> <body> <div id="jump" style="color: black; font-size: 32pt; position: relative;" onclick='jump()'>Jump!</div> <script> function jump() { var myStyle = document.getElementById("jump").style; myStyle.bottom = "0.5in"; myStyle.color = "red"; setInterval(function() {myStyle.bottom = "0in"; myStyle.color="black"}, 5000); } </script> </body> </html>

-- Apr 28 In-Class Exercise Thread

&lt;nowiki&gt;&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Dat Nguyen&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id=&quot;myJump&quot; style=&quot;font-size: 32px; color: black&quot; onclick=&quot;jump()&quot;&gt;Jump!&lt;/div&gt;

<script type="text/javascript">
	function jump() {
			var myElement = document.getElementById("myJump");
			myElement.style.bottom = "10px";
			myElement.style.color = "red";
			var revert = setTimeout(function() {
				myElement.style.bottom = "0px"; 
				myElement.style.color = "black";
			}, 5000);
		}
</script>

&lt;/body&gt; &lt;/html&gt;&lt;/nowiki&gt;

(Edited: 2021-04-28)
<nowiki><!DOCTYPE html> <html> <head> <title>Dat Nguyen</title> </head> <body> <div id="myJump" style="font-size: 32px; color: black" onclick="jump()">Jump!</div> <script type="text/javascript"> function jump() { var myElement = document.getElementById("myJump"); myElement.style.bottom = "10px"; myElement.style.color = "red"; var revert = setTimeout(function() { myElement.style.bottom = "0px"; myElement.style.color = "black"; }, 5000); } </script> </body> </html></nowiki>
[ Next ]
X