Week 4

Homework: Calculators

Solution

Homework is due on Thursday, August 20th.

Your task is to write four functions that will make three calculators work:

Download the ZIP to get started. You'll see an index.html file. That's where your code will go. There's actually a place at the bottom that shows you exactly where to put your code. You have to use your developer tools to complete this assignment. The four functions you're writing can't just be called anything. They must be called certain things and they must take certain arguments. That's what you need to figure out. They also must each return a number. Once they return the right number, you'll see that number appear in the interface.

Still confused? Message Danaan ;^D j/k/j/k! Try putting this inside the script tag:

  
    function calcFahrenheitToCelcius() {
      return 5;
    }
  

For those that want a sneak peak of what's to come, study the interface.js.

Resources

Forms

Forms are how we manage data we are going to send to the server. The entire form content is wrapped in a <form> tag. Forms have attributes that describe how they should interact with the server - the most important of these are method (which describes the HTTP method to use) and action (which describes where the data should be sent). See MDN's form reference for a complete list and more details

The form's data are stored in <input> tags to allow for user interaction. There are many types of <input> tags and related attributes, see MDN's reference on inputs for a comprehensive list of input types and other related input attributes.

<input> tags are labeled by <label> tags. You can use the for attribute on your <label> tag to reference the labeled input element's id.

Why do we need programming languages?

Variables

In programming languages, information is stored in things called variables.

in Javascript variables are created using the keyword var. For example: var x = 1;

Variables can store different types of data, for example:

Operators

In the above example (var x = 1;), we call the equals sign (=) the "operator". The operator = assigns a value to a variable. The above example assigns the value 1 to the variable x.

There are other operators used to manipulate values, for example: +, -, *, etc.

Functions

Functions fundamentally have three parts:

For example:

function sum(a, b) {
var result = a + b;
return result;
}

Functions are called with parentheses, for example, the following returns the number 5:

sum(2, 3);

Javascript and the browser provide you with a bunch of functions you can use to do things. You can find a complete list at MDN. Some examples (try them out!):

Javascript Language Rules