For the complete documentation index, see llms.txt. This page is also available as Markdown.

1-5 Javascript

What is Javascript?

-Javascript is a dynamic, object based programming language -Works with your HTML and CSS -Used to make websites interactive and also used in video games

Variables

  • Variables are names that are associated with a value and that value can change.

  • In JS, you can use variables to hold the values of text/string, numbers, or objects.

  • A variable is used to store information for later use, similar to storing values for x and y in algebra.

  • Start by declaring the variable in your JS code like this:

Variable Naming Rules

The key to using variables it to give them a meaningful name, so that it is easy to understand in your code.

Rules:

  1. Must begin with a letter

  2. Names are case sensitive (Ex: FirstName does not equal firstName)

  3. No spaces in the name - if using multiple words just put them together

  4. Start with a lowercase letter and capitalize the first letter of any other words used in the name (Ex: firstName, lastName)

  5. Make sure the name is meaningful (Ex: firstName means more than x or y)

Additional HTML Elements

Input - gives the user a textbox to type into

Button - used to allow the user to make something happen

functionName() will connect to a function that is in the Javascript.

Functions in JS

Functions are blocks of code designed to perform a specific task.

Functions are executed when something calls it (clicking a button, clicking a hyperlink, hovering, etc.)

For example, if you are on Amazon placing an order, when you click Submit your order is processed. Clicking the Submit button would call a function that would process your order (charge your credit card, ship the order, etc.).

Function Syntax

Assignment

Standard Deliverable

1) Use the Codepen we created together as a starting point. If you don’t have that, you can click here.

2) Add or change the following things about your website:

3) Make sure you test your website to make sure it looks and works like you want it to. Double-check that your welcome message displays with good punctuation, spelling, and spacing.

4) You can submit a link to your codepen. Be sure to save your work occasionally!!

Additional Activity

Print this document and follow the instructions.

Last updated