Using Multiple if statements

You can use more than one if statement in your code. Here’s an example of a calculation that uses two if statements. Let’s compute the total cost of an item where the price is based on the weight of the item. If the item weighs less than 1 pound then the price is 1.45 a pound. If the item weighs 1 pound or more the price is 1.15 a pound.

Edit the code above and change the first line so that weight has a different value. Run it again and see what changes. Try it in the codelens as well to see how the different values for weight changes the lines of code that are executed.

In this second version, we set a price as a default, then change it only on the special condition. Does it work the same as the above example?

Mixed up programs

You have attempted of activities on this page