JavaScript codes to copy and paste


Just select a block of code, then copy and paste it in de Sandbox from the url here below:
Open the link in a new tab page to switch easy between the tab pages of the Snandbox and JavaScript codes

Go to the Sandbox to play with Codes
  


<!--The Write Method--> <script> document.write("<b> Aquatic plants </b><br>"); document.write("Aquatic plants come in many varieties"); </script>


<!--Assigning variables and the Write Method--> <script> sweater1 = "Red"; sweater2 = "Green"; document.write("The colors are:", "<br>", sweater1, "<br> and <br> ", sweater2); </script>


<!--The Onload Method--> <script> window.onload = amessage(); function amessage(){ alert("Maps with pictures of aquatic plants"); } </script>


<!--The Prompt Method--> <script> input=window.prompt("What is your favorite color ?",""); document.write("Welcome. Your favorite color is: ", input,". Thank you!"); </script>


<!--A Timer function--> <script> function melding(){ alert("Wait a little longer"); } </script> <button onclick="setTimeout(notification, 3000)">Click here to view the timer</button>


<!--Changing the backgrond color of webpage--> <script> function backgroundcolor(){ document.body.style.backgroundColor = "red"; } </script> <button onclick="backgroundcolor()">Change background color</button>


<!--The use of id--> <script> window.onload = function (){ document.getElementById("link").style.color="green"; document.getElementById("link").style.fontFamily="verdana"; document.getElementById("link").style.fontSize="1.5em"; } </script> <a id="link" href="aquaticplants.nl">Beautiful aquatic plants</a>


<!--The use of id with a variable--> <script> window.onload = function () { var div = document.getElementById("blackyellow"); div.style.backgroundColor="yellow"; div.style.position="absolute"; div.style.left="200px"; div.style.top="100px"; } </script> <div id="blackyellow"> Text with yellow background color </div>


<!--The use of an function, with a variable and id--> <script>window.onload = function () { var div = document.getElementById("textfont"); div.style.color="#00FF00"; div.style.fontFamily="verdana"; div.style.fontSize="2.5em"; } </script> <div id="textfont"> <p>Text color, text type, and text size</p></div>


<!--The use of an function, with id and mouseover--> <script> function textcolor() { document.getElementById("color").style.color="#0000ff"; } </script> <button type="button" id="color" onmouseover="textcolor()"> Slide here with the mouse pointer to change the color of the text </button>


<!--The use of loops-->
<!-- The For loop --> <script> var i = 0; window.onload = function(){ for(i=0; i<5; i++){ document.write('Hallo<br>'); } document.write("it works"); } </script>


<!-- The Do while loop--> <script> window.onload = function(){ var i = 0; { i++; document.write("Hallo<br>"); } Please note! while just after accolade while ( i < 5) document.write("it works"); } </script>


<!-- The While loop--> <script> var i = 0; window.onload = function(){ while ( i < 5){ i++; document.write("Hallo<br>"); } document.write("it works"); } </script>


<!-- The Do break loop--> <script> window.onload = function(){ var i = 0; do{ i++; if (i==3){ break; } document.write("Hallo<br>"); }while (i<5); document.write("it works"); } </script>


<!-- The Break loop--> <script> var i = 0; var n = 0; while (i < 10) { i++; if (i == 6) { break; } n += i; document.write('<br>'); document.write(n); } </script>


<!-- The Continue loop--> <script> var i = 0; var n = 0; while (i < 10) { i++; if (i == 6) { continue; } n += i; document.write('<br>'); document.write(n); } </script>