Programming Warm-Up ⏱
The Big Picture
A program can be defined simply as a set of instructions that perform defined tasks, and we can use the diagram below to frame the major components of a program. A program can be written to accept particular inputs, like a mouse click, sound from a microphone, or a reading from a temperature sensor. The same program can handle the storage and retrieval of data, like to do items or historical temperature data. The same program can then output something useful, like a current to do list or move robot wheels. Multiple functions are written to control and process everything towards some useful end, each function handling a particular task.
Consider planning an in-class activity where students diagram a computing application (whether a social app, an AI driven tractor, or a video game console). Have them consider what inputs, data, and outputs the program includes. While the students will not know exactly how the engineers designed the application, they can come up with some specific function names to guess how the application processes the information. For example, a phone may have a function called "changeScreenBrightness" that takes the light sensor input to update the screen's brightness (output) based on a stored user preference (data).
Programming Languages
This exercise will use JavaScript, the primary programming language for web applications that work in a standard browser. There are many other popular programming languages. A particular language is chosen for implementation based on several factors related to the context of the need. Here are a few you may have heard of -- Python, Java (different from JavaScript!), Arduino, C++ and C#. Note: While HTML and CSS are languages with a defined syntax, they are usually distinguished from programming languages that provide computation and functions.
Let's Program: Variables, Functions, Conditionals, and Objects
This exercise takes a direct approach to prepare you for programming a CxD project by taking an "application first" perspective. We will frame this introduction by creating a simplified To Do Application using Javascript.
You are highly encouraged to build (and experiment with) the program as demonstrated in the video to get a feel for the programming. Also, remember to also try some online tutorials as a supplemental experience as explained in the Workshop Prep.
Declare Variables and Use a Built-in Function
First, in our script.js file, let's declare some variables of different data types and set their values.
todo
is a stringtime
is a numberisComplete
is a boolean (true or false).
Then we use a built-in function console.log()
to display the values.
Define a Custom Function
Here we define a custom function displayTodos()
. This allows us to call (or invoke) the function whenever we want.
Use a Conditional Statement
Here we use a conditional statement (using if/else) to customize the output.
Use an Object
Here we will use a single object variable to hold all the data for a particular to-do item.
JavaScript Arrays
Make a List (or Array)
Here we will use an array and for-loop to list multiple to-do items. We will ignore the time and completion data for now.
Make an Array of Objects
Here we will combine our use of an array with objects. This is the most difficult concept of this exercise and may take some time to digest. But it demonstrates a lot of powerful programming concepts in a very small program. 🚀🚀🚀🚀
Wrap-Up
That's our warm-up. Whether you found these concepts incredibly difficult or mostly review, please don't hesitate posting questions along with a link to your replit code in our Slack channel for the workshop.
Last updated