Skip to content

Week 2 JavaScript Functions

Mary Alice Moore edited this page Jun 4, 2024 · 1 revision
Week Topic Learning Objectives Key Resources
2 JS Functions Students will be able to encapsulate code with functions, pass information into functions, and practice with arrow functions. Week 2 Slides TBD

Overview

  • Function Basics

    • Functions bundle reusable code into callable packages. Define with function name() {} and call with name(). Can pass data in as parameters and return data out.
    • Functions create local scope for variables. Use return to pass data out of a function back to caller. Can also return function calls.
    • Arrow functions () => {} are a shorthand form for defining functions. Understand function call stack and order of operations when chaining function calls.
  • Practice with date and time functions

    • Create Date objects, access and modify date components like day, month, year, hours, etc. Calculate differences between dates in milliseconds. Format dates as strings.
    • Get the current date and time with new Date() and Date.now(). Use date methods like getDay(), getHours(), etc. and set methods like setDate() to manipulate Date objects.
    • Benchmark date functions for speed comparisons. Pass dates into functions as arguments. Be aware of browser optimizations when microbenchmarking.

Guidance for Mentors

  • Note that this week's mindset assignment asks students to think about the uses and misuses of AI in coding. Feel free to lead conversations on this topic in your sessions!
  • Common trouble spots here revolve around syntax, scope, data types/casting, conditionals and user inputs. Students should take it slow, use console logging, handle errors correctly, and ask for help early when stuck!

Assignment Rubric

You can mark the student's assignment as complete if they:

  • Fork the Replit file and submit their own link.

  • Use proper syntax and good JavaScript logic to answer the questions. Example outputs: (Note that some student work variation is expected!)

    • Q1: Welcome to Code the Dream!
    • Q2: [Current month]
    • Q3: Good Evening
    • Q4: [ANY ALL-CAPITALIZED TEXT]
    • Q5: I changed this and I started this
    • Q6: 10 (Can be other numbers - should be a multiplication!)
    • Q7: 3.5 (Can be other numbers – should be an average!)
    • Q8: console.log("Q8 neg num: ", absDiff(-6, 5) would yield Q8 neg num: 11
    • Q9: 5 (Can be other numbers - should be longest string)
    • Q10: 41 (Should display number of days until birthday)
    • Q11: 2 hours and 42 minutes (Should display time difference)
    • Q12: Variable student answers.

Key Pages

Overview of the wiki.

Onboarding guide for new volunteers.

Links to pages for specific assignments, including rubrics, overviews of student content, and mentor-created resources.

Clone this wiki locally