
HELLO WORLD.............................................................................................................. 3 AN INTRODUCTION TO COMPUTER PROGRAMMING........................................................... 3 WHY "HELLO WORLD?".................................................................................................. 3 JAVASCRIPT: YOUR FIRST PROGRAMMING LANGUAGE...................................................... 3 Interpreted languages and your Latin friends ............................................................ 4 Distancing yourself from the computer....................................................................... 5 THE TOOLS YOU'LL NEED......................................................................................... 6 1: A TEXT EDITOR ............................................................................................................ 6 2: A WEB BROWSER ......................................................................................................... 7 3: A JAVASCRIPT REFERENCE........................................................................................... 7 4: A WORKING DIRECTORY .............................................................................................. 8 5: AN HTML EDITOR (OPTIONAL) ................................................................................... 9 YOUR FIRST PROGRAM.............................................................................................. 9 TEMPLATE CODE............................................................................................................ 10 THE REMAINDER ............................................................................................................ 11 Objects...................................................................................................................... 11 Methods..................................................................................................................... 11 WRITING VALID PROGRAMS.................................................................................. 12 SEMANTICS .................................................................................................................... 12 SYNTAX ......................................................................................................................... 12 Programs must begin with “<script language=”javascript”>”............................. 13 Programs must end with “</script>”...................................................................... 13 Javascript is case sensitive....................................................................................... 13 Javascript allows comments..................................................................................... 13 Javascript ignores whitespace .................................................................................. 13 Javascript programs are lists of statements separated by semicolons ..................... 13 DESCRIPTION OF “DICE” ......................................................................................... 14 QUESTIONS .................................................................................................................... 17 PROGRAMMING CONCEPTS ................................................................................... 17 VARIABLES .................................................................................................................... 18 Integers / Floats........................................................................................................ 18 Strings ....................................................................................................................... 18 Booleans.................................................................................................................... 18 Arrays........................................................................................................................ 19 IF / ELSE......................................................................................................................... 19 Page 1 of 36 If-else ladder ............................................................................................................. 20 Code blocks............................................................................................................... 20 CASE.............................................................................................................................. 20 The switch ................................................................................................................. 21 The case statement.................................................................................................... 21 The default................................................................................................................. 21 FOR / BREAK / CONTINUE ............................................................................................... 22 The initializer ............................................................................................................ 22 The conditional ......................................................................................................... 22 The iterator ............................................................................................................... 22 Continue.................................................................................................................... 22 Break ......................................................................................................................... 23 COMMENTS .................................................................................................................... 23 FUNCTIONS / RETURN ..................................................................................................... 23 Name......................................................................................................................... 24 Parameters................................................................................................................ 24 Body .......................................................................................................................... 24 Return value.............................................................................................................. 24 WHILE / DO … WHILE .................................................................................................... 25 OPERATORS.................................................................................................................... 26 A LARGE EXAMPLE: SHUFFLING CARDS........................................................... 26 CODE SUMMARY............................................................................................................ 29 Using functions properly........................................................................................... 30 Program variables .................................................................................................... 31 Function addCards()................................................................................................. 32 Function getRandomNumber() ................................................................................. 34 Function shuffleTwoCards()..................................................................................... 34 Function shuffle()...................................................................................................... 34 The remainder........................................................................................................... 34 The results................................................................................................................. 35 YOUR PROGRAMMING FUTURE............................................................................ 35 Page 2 of 36 Hello World An introduction to computer programming Scared yet? Well don't be. Computer programming scares beginners away for two reasons: the massive "introduction" to computer programming tomes, and the beginners themselves. With your help, I would like to confront both issues. If I said that you could read a 2092 page "Gray's Anatomy in 21 days" to become a proficient surgeon, would you believe me? Would you blame yourself if you tried and failed? I hope you answered an emphatic "no" to both questions. Similar statements plague introductions to computer programming. Unfortunately, many early programmers sit down with huge books to learn programming all at once. With your help, I would like to introduce you to computer programming If I told you that most people most people fail to learn computer programming because it is too simple, would you believe me? This time you should. Most people fail to learn computer programming because they try to do too much at once. A computer does anything you tell it to. Perfectly. But that's it. Computers never "get it" and run what you meant to type. If you want to make your computer do something, you tell it with a language that uses only small, precise, and un-ambiguous commands. With your help, I would like to help you begin to understand one of the small, precise, and un-ambiguous languages. In fact, I would like to help you begin to understand all of them. Why "Hello World?" In 1973, Brian Kernighan wrote the paper, "A Tutorial Introduction to the Language B." In it, Kernighan wrote several small B programs to illustrate important
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages36 Page
-
File Size-