Skip to main content
Menu
CodeBabes
  • Create new account
  • Request new password

or

  • Sign in with Twitter
  • Code
  • Babes
  • Sign Up
  • Log In

Looks like you missed a quiz. Go back and pass that shit!


NO STRIP FOR YOU!

Share the Love

  • Tweet

Programming Intro Conditional Statements

Ok, I kept my promise. You made it to the next lesson so the cardigan came off. The topics are going to have to get harder before things get serious.

Let’s talk conditional statements. Programming usually comes down to making decisions based on some kind of input. If something happens, or something is true, then perform an action based on that condition.

Let’s do an example to show how if-statements work. But first we’ll put a comment about what this if statement will be doing. “How to get my number”.

Let’s talk about comments for a hot minute. Comments are prevalent in all programming languages. They allow users to make notes about the code they are writing. The comment is ignored by the program. For human consumption only. Comments in javascript come in two varieties. Double forward slashes comment out a single line. You can create a multi-line comment like this.

Back to getting my number. Let’s set up an if statement first. We’ll start with me being really picky. So if dude is equal to Ryan Gosling then dude gets my number and email. Because, well c’mon. (beat) The stuff inside the parentheses will evaluate to a boolean value. That just means it will be true or false. If it’s true, then the stuff in the curly braces happens. The double equals sign is a comparison operator testing whether the two things are equal. Always remember in javascript that you need two equal signs to test if two things are equal. The single equal sign sets a value to a variable.

Let’s set the variable dude equal to Ryan Gosling like this. (gesture)

Then we’ll run the script and my phone number and email will be logged to the console.

But what if the dude isn’t Ryan Gosling? Well, then we could add else to the if statement like this.

If you’re not Ryan Gosling, then I’ll have to think about it.

That’s pretty picky though. To give some more guys a chance we can add the ‘else if’ statement and change the dude variable to nice guy. Then we add a condition after else-if like this:

The 'exclamation point equals' is a comparison operator that stands for Not Equal. So if dude is NOT equal to douchebag, then you get my number. But we’ll still need an else statement for guys who aren’t Ryan Gosling and are douchebags. For those guys we’ll output “I’m kind of busy for the rest of my life.

There are a bunch of operators we can use for comparing two values. If we were comparing two numbers, we could use greater than and less than operators like this.

In the next lesson, we are going to talk about arrays. You probably want to stick around.

Questions or Comments?

Lessons

  • Variables in Programming
  • Programming Intro Conditional Statements
  • Programming Intro to Arrays
  • Programming with Loops
  • Programming with Functions
Programming Virgin with Javascript

Downloads

SignUp & Subscribe

What the What?

Lessons: 41

Much more to come!

50/50 Entertainment and Education. Learning doesn't have to be boring :)

Our Philosophy

Contact

  • support
  • Tweets!
  • Youtube
  • Google Plus
  • Facebook

Stuff

  • Blog
  • Sign Up
  • All Babes
  • All Courses
  • Become a CodeBabe!
  • MAKE A LESSON WITH CODEBABES!

Recent Courses

Internet Virgin
SEO Virgin
HTML Virgin
CSS Virgin
Programming Virgin with Javascript

Learn to Code with Babes

Copyright © 2025 CodeBabes.com • Made with

  • Privacy Policy
  • Terms of Use
Close Menu
  • Blog

  • All Courses
  • Android Virgin
    • Android Studio Tour
    • App Layout in Android Studio
    • Java Variables, Java Data Types & Android Views
    • Java Event Handling in Android
    • Android Intents, OOP This, Variable Scope
    • Passing the Data with Android Intents & Finish
    • Complete the Android App with Launcher Icons & APK
    • Android Happy Ending
  • Internet Intro
    • Backend Development
    • Front End Web Development
    • Programming Tools you Need
    • Hosting and Domain Names
  • HTML Virgin
    • HTML Text Tags
    • HTML Links and Images
    • HTML Layout with HTML 5
    • HTML Tables
  • CSS Virgin
    • Where to Stick your CSS
    • CSS Properties, Sizes and Colors
    • CSS Selectors
    • CSS Box Model
  • Programming Virgin
    • Variables in Programming
    • Programming Intro Conditional Statements
    • Programming Intro to Arrays
    • Programming with Loops
    • Programming with Functions
  • PHP Virgin
    • PHP Variables
    • PHP Conditionals
    • PHP Arrays
    • PHP Loops
    • PHP Functions
  • SEO Virgin
    • Make Google Love You
    • Understanding Keyword SEO
    • Optimizing for SEO
    • Technical SEO