VNUHCM
Bài trước Bài kế tiếp
  • Nội dung học
  • Trợ giúp
    Bạn có thắc mắc khi đang học?
    Hướng dẫn cách học Những câu hỏi thường gặp Email cho giáo vụ
    • Tiếng Việt
    • English
    • Thông tin Thành viên
    • Khoá học đăng ký
    • Đăng xuất
  • Cohota
  • HƯỚNG DẪN HỌC TẬP

  • Xem chi tiết >>
    Bạn đã hoàn thành 0% khoá học
  • HƯỚNG DẪN SINH VIÊN ĐĂNG NHẬP HỆ THỐNG
    • Hướng dẫn đăng nhập
    • Hướng dẫn vào khóa học
  • Introduction
    • Welcome
  • Unit 1: Values
    • Introduction - Unit 1: Values
    • Get Started With Values
    • Play with Values
    • Playground Basics
    • Naming and Identifiers
    • Simulation
    • Strings
    • Constants and Variables
    • Word Games
    • Build a PhotoFrame App
    • Design for People
  • Episode 1: The TV Club
    • Introduction - Episode 1: The TV Club
    • Searching for Content
    • Sharing Personal Information
    • Ordering Online
    • Reflection: Episode 1
  • Unit 2: Algorithms
    • Introduction - Unit 2: Algorithms
    • Get Started with Algorithms
    • Play with Programs
    • Functions
    • Types
    • Parameters and Results
    • Making Decisions
    • BoogieBot
    • Data Visualization
    • Build a QuestionBot App
    • Design an Experience
  • Episode 2: The Viewing Party
    • Introduction - Episode 2: The Viewing Party
    • Accessing the Show
    • Streaming on the Network
    • Reflection: Episode 2
  • Unit 3: Organizing Data
    • Introduction - Unit 3: Organizing Data
    • Get Started with Organizing Data
    • Play with Complex Data
    • Instances, Methods, and Properties
    • Arrays and Loops
    • Structures
    • Enums and Switch
    • Testing Code
    • Processing Data
    • Pixel Art
    • Password Security
    • Visualization Revisited
    • Build a BouncyBall App
    • Design a Prototype
  • Episode 3: Sharing Photos
    • Introduction - Episode 3: Sharing Photos
    • Capturing Images
    • Posting on Social Media
    • Reflection: Episode 3
  • Unit 4: Building Apps
    • Introduction - Unit 4: Building Apps
    • Get Started with App Development
    • Play with App Components
    • Color Picker
    • ChatBot
    • Rock, Paper, Scissors
    • MemeMaker
    • Build an ElementQuiz App
    • Design for Impact
  • Appendix
    • Episode Technical Concepts
    • Glossary
Tổng quan điểm khóa học
Đánh giá

Tiến độ
Tên tiêu chí Trọng số (%) Điểm Tiến độ (%)
Unit 2: Algorithms

Making Decisions

Unit 2: Algorithms|Play

What you'll build

  • A program to determine if a given year is a leap year.

What you'll learn

  • How to compare values.
  • How to use the results of comparisons to choose which lines of code to run in your apps.

Key vocabulary

  • Boolean
  • Comparison operators
  • Conditional statement
  • Remainder operator, %
  • if statement
  • if-else statement
  • else if

Introduction

Imagine you’re asked to make dinner and given a bunch of ingredients. Depending on the ingredients, you’ll follow a different set of steps. If you have lettuce, you’re not going to put it on the grill. In this lesson, you’ll learn how to add decision-making capabilities to your programs, so they can do different things depending on the information they’re given.

Go Build

Open the Making Decisions.playground file in your course resources and follow the instructions.

Screenshot of the MakingDecisions playground

Reflection Questions

Think of a set of instructions you’d write ​for someone looking after your cat for ​the day.

How many of the steps would ​have conditionals attached to them? For example, if the food bowl is empty, you’d want them to top it up.

Almost every task involves making a decision.

Can you list ​out the decisions you make when getting ready in the morning?

What information ​do you need?

What different things do you do as a result of those decisions?

Summary

Using if and else statements represents an important fundamental technique in program development. When your code can make decisions based on the information it’s given, your programs will be able to solve a variety of interesting problems. 

Conditionals make your programs more powerful but also make them more complicated. To keep your programs understandable and manageable, you can use functions to hide complicated or multistep decisions.

Next, you'll look at a fun way to apply your knowledge to power a dancing robot.

Báo lỗi