Let’s recreate the conditional control structure using JavaScript! (The one about social media posts, remember?)

Diagram of conditional control structure

The control flow shown above is written as a conditional control structure in main.js. It looks something like this:

if (condition) { DO SOMETHING } else { DO SOMETHING DIFFERENT }

If the condition evaluates to true, the computer will execute the body of that statement. In this case, it’s DO SOMETHING.

If the condition is false, the computer will execute the body of the else statement. In this case, it’s DO SOMETHING DIFFERENT.

Let’s adapt this general template to our example:

  1. The condition is true when the privacy mode is set to 'public'. This is already written for you in main.js.
  2. You’ll replace DO SOMETHING with a JavaScript function: showDetails().
  3. You’ll replace DO SOMETHING DIFFERENT with another function: hideDetails().

The instructions below will show you how to do this in code!


Complete the control structure by calling the functions below. If the mode is 'public', call:


Else, call:


Run the code and test the website.

If done correctly, the content of the post should be visible when you choose “Make Profile Public” in the dropdown, and the content of the post should be hidden when you choose “Make Profile Private”.

Take this course for free

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?