Key Concepts

Review core concepts you need to learn to master this subject

Conditional Control

Conditional statements or conditional control structures allow a program to have different behaviors depending on certain conditions being met.

Intuitively, this mimics the way humans make simple decisions and act upon them. For example, reasoning about whether to go outside might look like:

  • Condition: Is it raining outside?
    • If it is raining outside, then bring an umbrella.
    • Otherwise, do not bring an umbrella.

We could keep adding clauses to make our reasoning more sophisticated, such as “If it is sunny, then wear sunscreen”.

Functions
Lesson 1 of 2
  1. 1
    This lesson requires you to know the basics of hamburger-making: * Place the bread down * Add the burger patty * Add the pickles * Place the bread on top What if you had to say each step every tim…
  2. 2
    Instead of giving those instructions for every hamburger, we can group and name them as a single function: function makeHamburger() { Add bread Add burger patty Add pickles } A function …
  3. 3
    Not everyone wants to eat hamburgers. We could write a new function for each new sandwich type, but that takes a lot of work and risks making mistakes. Instead, we’ll generalize the hamburger f…
  4. 4
    A sandwich wouldn’t be complete without fries and dessert! Here are the instructions to make the complete meal: * Add bread, Add burger patty, Add fried potatoes, Add pickles, Add bread, Add salt…
  5. 5
    Time to get coding! It’s okay if you don’t recognize all the symbols in this code: we’ll walk you through the parts you need to know. The makeSandwich() function is provided in main.js. It is …
  6. 6
    Well done! Functions are a fundamental concept in programming, and learning the basics will serve you wherever your path leads, regardless of language or domain. To review: * A function is a sequ…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo