Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>JavaScript in 12 Minuets</title>
- </head>
- <body>
- <h3>document.write</h3>
- <script>
- document.write("Hello, World!");
- </script>
- <br>
- <h3>variables</h3>
- <script>
- var myvariable = 5; // this can be a number, a string or bolean
- </script>
- <br>
- <h2>variables with operators </h2>
- <h3>concontinate = to add them together</h3>
- <script>
- var words = "This is";
- var moreWords = " a sentence";
- var sentence = words + moreWords;
- document.write(sentence);
- </script>
- <br>
- <br>
- <h3>totaling by adding, subtraction, multiplying and division</h3>
- <script>
- var num1 = 5;
- var num2 = 3;
- var total = num1 + num2; // subtract -, add +, divied /, multiply *, find the remainder after with %, if you use ++ will add 1, -- will subtract 1
- document.write(total);
- </script>
- <br>
- <br>
- <h3>Strings are stored as objects</h3>
- <script>
- // This is an objet - just information
- var alpha = "ABCDEFG"; // string
- var length = alpha.length;
- document.write(length);
- document.write("<br>"); // adds a break between the html lines
- // This is a methode, it can take input, do computation, and then output the answer, substring will take a portion of the string,
- var result = alpha.substring(0, 5);
- document.write(result);
- </script>
- <br>
- <br>
- <h3>Arrays</h3>
- <!-- Arrays hold many values in a single variable -->
- <script>
- var a = new Array(7);
- a[0] = "cat";
- a[1] = "dog";
- a[2] = 95;
- a[3] = "something else";
- a[6] = true;
- document.write(a[1]);
- </script>
- <br>
- <br>
- <!-- the same array but written shorter -->
- <script>
- var a = new Array("cat","dog", 95, "something else", true);
- document.write(a[1]);
- </script>
- <br>
- <br>
- <!-- and another shorter way with the same array -->
- <script>
- var a = ["cat","dog", 95, "something else", true];
- document.write(a[3]);
- </script>
- <br>
- <br>
- <h2>defining functions</h2>
- <!-- functions can be called to be reused, good habit to be able to reuse functions -->
- <script>
- function sayHello(who) {
- document.write("Hello");
- }
- </script>
- <!-- you call the function like this below someplace within the body -->
- <script>
- sayHello();
- </script>
- <br>
- <br>
- <h2>defining functions with more than one variable</h2>
- <!-- functions can be called to be reused, good habit to be able to reuse functions, they can also be used like below with multiple variables -->
- <script>
- function sayHello(who) {
- document.write("Hello, " + who);
- }
- </script>
- <!-- you call the function like this below simeplace within the body -->
- <script>
- sayHello("Bob");
- document.write("<br>");
- sayHello("Mary");
- </script>
- <br>
- <br>
- <h2>flow control statements - if statements object-numeric</h2>
- <script>
- var a = 12;
- if (a > 10) { // < less than, > greater than, >= greater than or equal to, <= less than or equal to, != not equal to, == equals (last two for strings)
- alert(a);
- }
- </script>
- <br>
- <br>
- <h2>flow control statements - if statements as a string</h2>
- <script>
- var a = "jake";
- if (a == "Jake") { // < less than, > greater than, >= greater than or equal to, <= less than or equal to, != not equal to, == equals (last two for strings)
- alert(a);
- } else {
- alert("The condition was false");
- }
- </script>
- <br>
- <br>
- <h2>flow control statements - for loop </h2>
- <script>
- for (i=0;i<5;i++) { // counter variable, condition (< than 5), increment i or the counter variable) it will produce results going from 0 thru 4
- document.write("This is iteration " + i + "<br>"); // this concantinates the string with the current value of i and then concantinate the html line break <br> to make the output neater and more readable
- }
- </script>
- <br>
- <br>
- <h2>flow control statements - for loop, same as above but with change in counter </h2>
- <script>
- for (i=1;i<6;i++) { // counter variable, condition (< than 5), increment i or the counter variable) by changing the counter variable from 0 to 1 and the condition from 5 to 6 it will produce results going from 1 thru 5
- document.write("This is iteration " + i + "<br>"); // this concantinates the string with the current value of i and then concantinate the html line break <br> to make the output neater and more readable
- }
- </script>
- <br>
- <br>
- <script>
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement