If you're seeing this message, it means we're having trouble loading external resources on our website.

Jeżeli jesteś za filtrem sieci web, prosimy, upewnij się, że domeny *.kastatic.org i *.kasandbox.org są odblokowane.

Główna zawartość

Wskazówki dla nauczycieli: funkcje w JS

To jest podręcznik nauczania dla kursu Wprowadzenie do JS dla dziewiątego rozdziału dotyczącego Funkcji.

Czego uczniowie się nauczą

  • Jak definiować ich własne funkcje, aby mogli łatwiej grupować ten kod i wywoływać go wiele razy.
  • Jak definiować parametry ich własnych funkcji, aby za każdym wywołaniem rysowały coś z minimalnymi różnicami.
  • Jak zwracać wartości z ich funkcji, aby mogły liczyć czy generować ciągi.
  • Poznają ważną różnicę między zmiennymi globalnymi a lokalnymi.
  • Poznają różnicę między ich własnymi funkcjami, które definiują, a specjalnymi funkcjami ProcessingJS, które re definiują, takimi jak draw().

Uczniowie nauczą się pisać kod taki jak:

Z czym uczniowie mają kłopoty

  • Students don’t always understand the motivation behind grouping code into reusable functions. That’s likely because they haven’t coded large programs where they’ve repeated the same blocks of code multiple times. You can tell them that many programs are thousands of lines long, so there it’s absolutely necessary to have functions for the functionality the program does over and over. You can also check out a few programs from the community and see how they use functions.
  • Students are sometimes confused about the difference between custom functions and the ProcessingJS functions like rect(). On Khan Academy, we automatically include the ProcessingJS library in every program, and that library is a collection of already defined functions. That’s why every program can call those functions. Students can then define additional functions in their own programs, but they can only call them in the program where they’re defined.
  • Students may struggle to understand function parameters versus variables. When they call a function and pass in parameters, those then become local variables inside their function, with the names taken from the function definition. They can trace the values using println() at various points in their code. Here's an example program tracing common mistakes.
  • Students may not fully grasp what return does inside a function. For those students, after they do the Calculator challenge, encourage them to make functions that calculate other expressions, and display the results of those on the screen. Prompt them to remove the return statement or move it around to see what happens.

Dodatkowe materiały: zadania nie wymagające komputera

Zadanie "bez komputera" jest zadaniem, które twoi uczniowie mogą wykonać bez potrzeby używania komputera. Mogą pomagać w przekazaniu pomysłów w bardziej instynktowny sposób lub być aktywnością zapasową, gdy komputery z jakiegoś powodu przestaną działać.
Code.org offers a Functional Suncatchers activity (see lesson plan, overview video & in-class example video). This activity is probably better for younger students, older students may find it too slow.

Dodatkowe materiały: pytania do dyskusji

Są to pytania, które możesz zadać uczniom indywidualnie, gdy ukończą ten samouczek lub poprowadź dyskusję grupową, jeżeli każdy ukończył samouczek do tego samego momentu.
  • Ask students to think about their daily activities and what sequences of steps they repeat. If they could program themselves, what functions might they program?
  • Ask students to look at a previous project, and see if they can find blocks of code that would make sense as a function. If they ever drew multiple instances of the same object in a drawing, there's likely a good case for making a function!

Dodatkowe materiały: pytania i ciekawostki

Te pytania mogą być ciekawym zajęciem po tym, jak każdy uczeń ukończył samouczek. Mogą także prowadzić dyskusję na temat pytań, które sprawiły im trudność. Zagraj z nimi na Quizizz.

Chcesz dołączyć do dyskusji?

Na razie brak głosów w dyskusji
Rozumiesz angielski? Kliknij tutaj, aby zobaczyć więcej dyskusji na angielskiej wersji strony Khan Academy.