Learn

You made it to the end of the lesson! High five. 🙌

Here is a review of the lesson:

  • A variable represents a particular piece of your computer’s memory that has been set aside for you to use to store, retrieve, and manipulate data.
  • Variables are declared using the var keyword.
  • Constants are declared using the let keyword.
  • Swift basic data types include:
    • Int: integers
    • Double: floating-point numbers
    • String: a sequence of characters
    • Bool: true/false
  • Single equals sign = indicates assignment.
  • Arithmetic operators include +, -, *, /, %.
  • Compound assignment operators include +=, -=, *=, /=, %=.

Instructions

1.

Optional: The body mass index (BMI) is commonly used by health and nutrition professionals to estimate human body fat in populations.

It is computed by taking the individual’s weight in kilograms (kg) and dividing it by the square of their height in meters (m²):

bmi=weightheight2bmi = \frac{weight}{height^2}

Complete the BMI.swift program which calculates and prints an individual’s BMI. Store a weight, height, and BMI calculation in variables then print the BMI to the console.

(To skip, just click Run.)

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?