Programming in Dart: Fundamentals
Apr 26 2022 Dart 2.15, DartPad, DartPad
Part 1: Fundamentals
4. Challenge: Play with Booleans
This video was last updated on Apr 26 2022
It’s time to get started with your first Dart challenges. In this episode, you’ll get two of them. So lets get started in the first one. For your first challenge, I want you to create a variable called myAge and assign it your current age. Then create a constant called isVotingAge. Set with a boolean based on if your age is over the legal limit. Pause the video now and give it a shot.
How’d the first challenge go for you? Let’s go over it now. First start by creating a variable called my
const myAge = 47;
And then I need to check if my age greater than or equal to 18, the voting age.
const isVotingAge = myAge >= 18; print(isVotingAge);
And with that, we have a boolean value set in the voting age.
How’d that one go for you? Don’t worry if you didn’t get it. I have another one for you. Create a constant called student and set it to your name as a string. Then create a constant called author and set it to “Matt Galloway”, the original author of these exercises. Finally, create a constant called authorIsStudent that uses string equality to determine if student and author are equal. Pause the video and try it out.
How’d that one go? Feel free to follow along with me. OK, first I’ll set up the student and author constants:
const student = 'Brian Moakley'; const author = 'Matt Galloway';
And then to find of if the author and student have the same name…
const authorIsStudent =
I’ll use the double equals sign to check for equality.
const authorIsStudent = student == author;
And then, I’ll print out the result.
And that’s it - as you can see, I am not Matt Galloway. That’s it for this challenge! Next up, some more work with operators and Booleans.