Introduction To Programming We're using the JavaScript programming language to learn the basics of programming/development. This is a great language to learn with. All you need to use it is a modern internet browser, like Chrome or Firefox. You can use simple and free programs to write JavaScript called "text editors."
<script type="text/javascript">
//<!--[CDATA[
//<!--
// YOUR CODE STARTS AFTER THIS LINE:
// END OF YOUR CODE
// -->
//]]-->
</script>
//. That makes the line a comment that will be ignored by JavaScript.In computer programming, there are different levels of rules. Here are the three we are concerned with in this course.
Remember those rules about computers? They can't think and they can't figure out what you mean. You have to be very clear and you have to use their language, not yours. Programming languages are very simplistic compared to human languages, but they are very strict. You have to follow the rules of the language that are called its syntax. Here are some of the basic syntax rules of JavaScript.
In JavaScript, the word "IF" is not the same as "if". Everything has to be the correct case. This is a challenge for lots of beginning programmers. We have to start "seeing" the case of text as part of the meaning. Almost everything you learn in programming is case sensitive.
White space are characters you can type on the keyboard but you don't normally see on the screen or on paper when you print. Here are the white space characters:
In JavaScript, white space usually doesn't matter. Unfortunately, there's that word "usually" in that rule. There are some situations where it matters a lot. Therefore we're are going to have a course standard for using white space. Refer to the course JavaScript Coding Standards for 10-152-310 for more details.
Comments in our code are lines of text that are ignored by JavaScript. We use these to write notes to ourselves and other programmers who see our code. This is called Documentation.
There are two kinds of comments in JavaScript, single-line and multiline.
A single-line comment starts with two forward slashes: // Example:
A multiline comment starts with /* and ends with */. These can be over many lines. Example:
Semicolons are used in JavaScript to end a line. Most of the time they are not required by JavaScript. However, they are required in a few places so as a course standard, that is also a convention in the industry, the use of semicolons at the end of statements is required.
JavaScript statements are lines of text that contain tokens, operators, and identifiers that is understandable to the JavaScript interpreter. They are like the sentences of a programming language. When someone writes prose they write sentences that are organized into paragraphs. When we write JavaScript we write statements that are organized into blocks and functions. Here are some more details about statements.
Statements usually end with a semicolon ";"
Simple statements are one line that just does one thing:
There are a bunch of words that have special meaning to JavaScript. They are called Reserved Words. Because of this we can't use those words in our code. Here they are:
break |
delete |
function |
return |
typeof |
case |
do |
if |
switch |
var |
catch |
else |
in |
this |
void |
continue |
finally |
instanceof |
throw |
while |
default |
for |
new |
try |
with |
Let's do this lab: 2.1 Lab 2
Here is the 2.1 Assignment 1