Variables, Operators, and IO

Essence of computation

Adding code to HTML

Now we write some code -

output

Simple output - the alert box

Output statements will have some string (text) value which should be shared with the user

Example - hello world:

<html>
<script>
  //hello world
  //the classic first program
  alert("hello world");
</script>
</html>

Variables

variables -

Characterstics of a variable:

Creating a variable:

Using a variable:

Example - hello world with a variable

  <script>
    var theName = "Wally";
    alert "Hello!";
    alert theName;
  </script>

Example - an adding program

  <script>
    //Adder
    //adds up two values and returns the results
    var num1 = 5;
    var num2 = 7;
    var answer = 0;

    //add 'em up
    answer = num1 + num2;
  </script>

Input

modal input

Operators and functions for manipulating variables