Practice Set - Conditionals & Blocks within Braces
by russduza
HTML
<h3>Conditionals & Blocks within Braces</h3>
<h4>2 Tasks for this Practice Set:</h4>
<ol>
<li>Use conditionals to create code which outputs a sentence to the console stating whether the variable <i>x</i> is greater to, equal to, or less than zero. It should work for any numeric value of x</li>
<li>Look at the code in this section, and fix it so that the output is correct. In your console, it should look like this (Hint: it involves braces) :
<img src="http://courses.dce.harvard.edu/~cscie3/img/captains.png" title="program output" style="width:80%;padding-top:.5em;">
</li>
</ol>
JavaScript
"use strict";
// Insert your code for #1 here
var x = -2;
var greaterLessEqual = "Wow! " + x;
if (x > 0) {
greaterLessEqual += " is greater than zero!";
}else if (x < 0) {
greaterLessEqual += " is less than zero!"
}else if (x == 0) {
greaterLessEqual += " is equal to zero!"
}
console.log(greaterLessEqual);
// Insert your code for #2 here
var myCaptains = ["James T. Kirk", "Jean-Luc Picard", "Katherine Janeway"];
for (var i = 0; i < myCaptains.length; i++) {
system.out.ptintln((i+1) + ": ");
myCaptains[i] = userInput.nextLine().toUpperCase();
}