You have learn how to subtract binary numbers. However, this method is not suitable to implement in computer hardware. In this topic, you will learn how, using the same principles of binary addition, binary subtraction can be done. This method called Two's Complements can be easily be performed by computer hardware.

By the end of this lesson, you will be able to perform Binary Subtraction using Two Complements.

Estimated duration : 20 min


Lesson 1 of 11: Learning Objectives

By the end of this course, you will learn how to

  1. Use if statement to decide which lines of codes are executed (decision making).
  2. Use loop statement (for, while and do while) to repeat the execution of a block of codes.
  3. Apply the use of control statements in appropriate contexts.
  4. Use functions to group a block of codes for reuse.

Lesson 2 of 11: if statement

Decision Making.jpg

Decision Making

If you would only buy a car when you have $100,000, how would you express it in JavaScript using control statement?

Decision Making.mp4


If-else statement

How would you change the above control statement if I add in that if you have less than $100,000, then you would just buy a toy car?

if (money>100000)
  buyCar=true;
else
  buyToy=true;

You would add in the else statement as shown above. If the first condition (money > 100000) is not satisfied, the else block will be executed.

In this case, buyToy would be set to True when money is less than 100000.