Javascript: Functions ATLS 3020 - Digital Media 2 Week 4 - Day 2 - - PowerPoint PPT Presentation

javascript functions
SMART_READER_LITE
LIVE PREVIEW

Javascript: Functions ATLS 3020 - Digital Media 2 Week 4 - Day 2 - - PowerPoint PPT Presentation

Javascript: Functions ATLS 3020 - Digital Media 2 Week 4 - Day 2 Quiz #1 next Monday Structure: Topics covered: 30 minutes in-class Input/Output Open note, book, Creating arrays, deleting and internet, etc adding elements


slide-1
SLIDE 1

Javascript: Functions

ATLS 3020 - Digital Media 2 Week 4 - Day 2

slide-2
SLIDE 2

Quiz #1 next Monday

Topics covered:

  • Input/Output
  • Creating arrays, deleting and

adding elements from arrays

  • If-Else statements
  • For loops
  • Functions

Structure:

  • 30 minutes in-class
  • Open note, book,

internet, etc

  • Write a program

that follows a set of steps

slide-3
SLIDE 3

Project 1

Write a game in JavaScript. The game can be a guessing game, a calculation game, a quiz, or some other type of

  • game. Be creative!

Your project plan should include the following: Due Feb 9 ○ description of your project ○ pseudocode for algorithms and program flow ○ visual design template or example ○ brief description of how you will test your project

slide-4
SLIDE 4

Functions

Another way that to not repeat code Example: Music

Verse 1 Verse 1 Verse 1 Chorus Chorus Chorus Verse 1 Verse 1 Verse 1 Chorus

slide-5
SLIDE 5

Functions

function do_something () { // inside the function } // outside the function do_something(); Javascript

There are TWO key words!

  • 1. You must write the word “function”
  • 2. You must name the function (just like a

variable name) Calling a function Type the name of the function with parentheses afterwards.

slide-6
SLIDE 6

Functions with Parameters

function do_something (x, y) { // inside the function } // outside the function var a = 0; do_something(a, "red"); Javascript

Parameters

  • Put the variables you want to pass inside
  • f the parentheses
  • This creates two variables called x and y

Calling a function

  • You must have the same number of

variables as parameters

  • You can pass in variables or data values
slide-7
SLIDE 7

Lab 6

Continue playing the card game War!

  • 1. Copy your code from Lab 5.
  • 2. Create a new function that plays 1 round of the game. Copy your code from inside the for or

while loop and put it inside of the function.

  • 3. Create a function that removes (with splice) the first cards from both player’s decks.
  • 4. Create a function that prints the first cards of both player’s decks.