WDI Fundamentals

WDI Fundamentals Unit 8


Your Turn Your Turn

Check out the sample code in the JS Bin session below. If you don't see the JS Bin, please refresh the page.

JS Bin on jsbin.com

As in the previous exercise, your job is to print the result of an expression. However, this time your expressions will need to depend on the variable x.

  1. Write an expression that evaluates to 10 more than x;
    if x is 10, the expression should evaluate to 20;
    if x is 50, the expression should evaluate to 60.
    Test your answer by replacing the /* Your Expression */ comment in the JavaScript tab with x = someValue;, clicking the "Run" button, writing your expression in the Console tab, and typing enter or return.

2) Now, replace that first expression with an expression that evaluates to triple the value of x plus 5;
if x is 5, the expression should evaluate to 20;
if x is 10, the expression should evaluate to 35.
What happens if you set x to 100? Does the expression work like you'd expect?

3) Next, replace that expression with one that evaluates to "Hello, x.";
if x is "Alice," the expression should evaluate to "Hello, Alice.";
if x is "Bob," the expression should evaluate to "Hello, Bob.".

4) Finally, replace the prior expression with one that evaluates to "Goodbye, x.";
if x is "Charlene," the expression should evaluate to "Goodbye, Charlene.";
if x is "David," the expression should evaluate to "Goodbye, David".

Try out all of the different "test cases" mentioned above. If they all give you the answers you expected, you're done!

Stuck? Check out the solutions to see what you can do.


On to the next lesson!