Download presentation
Presentation is loading. Please wait.
1
Console
2
Two key uses Error Messages Print Stmts If you see an error message
Don’t panic Use it to help Like validation Tries its best Error often earlier Remember: JavaScript executes one statement at a time in order Track work Can leave it forever
3
Variables
4
Variable Values Save into a variable and the value changes Use a variable (like printing) and the value does NOT change
5
Illustration
6
JavaScript Function
7
What is a function? Collection of statements that can be invoked as a unit Because sometimes we want to do more that a single assignment!
8
Different Types of Functions
Who writes? JavaScript provides Someone else writes & you use You write
9
Does function need information?
Alert does…tell it what to write Asking for a random number doesn’t Always need to use () Pass data if needed () if not
10
Parameters Math.round: Number to round
Call a function with a different value every time MUST give it everything that it expects alert or console.log: string to print Math.round: Number to round
11
Statement or part of an expression
Alert is a statement; doesn’t give you anything back If you ask for a random number, you expect to get something back
12
Functions as Statements
Performs an action but doesn’t give you anything back Example: alert
13
Alert String to print Function
14
Writing a Function
15
Format of a Function functionName(parm,parm);
Always needs () even if no parameter functionName(); For now: no parameter
16
JavaScript Functions Summary
17
alert console.log Takes an input value (string)
Does not return a value
18
Getting a random number
Math.random() Does not need any inputs Returns a value between 0 and 1
19
Other math functions Take an input value (number)
Math.round(num) Math.floor(num) Math.ceil(num) Take an input value (number) Return a value (number)
20
Connecting JavaScript to HTML
21
Where Do JavaScript Functions Go?
Like CSS, can be inline or a separate file Like CSS, an external file is considered better practice Like CSS, link to it from the head section
22
A Separate JavaScript File
<script src="myscripts.js"></script> Myscript.js JavaScript option in komodo will work on it next
23
FUNCTION: connecting to HTML
<head> <script src=“function.js”></script> </head> <body> <button type=“button” onclick=“doit();”> </body> HTML file name function name function doit () { alert(“Hi!”); } JAVASCRIPT (function.js)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.