6.Solo flight


Hey, I do need some help. Can anybody respond to me as soon as possible?

//Remember to make your condition true outside the loop!
var number = true

var soloLoop = function(number){
  while(//I don't know what to put inside the loop) {
      console.log("Looped once!");
      number = false;



You going to want to kick me (but please don't)

while (number) {
    number = false;
    console.log("Looped once!");
}   // <<< be sure to add this closing curly brace


JavaScript variables have no defined type. Their type is determined by the values they hold or the objects they refer to. This makes it possible to coerce the variables to a new type.

What does that mean? It means a number can be coerced into a string, or a string into a number (might be NaN) and both of them can be evaluated as a boolean. To see what I mean, examine the following:

console.log(!"string");   // false
console.log(!42);         // false

! (called NOT, or negation operator) coerces variables to their boolean equivalent. Study these next examples and I'll explain further.

console.log(!"");         // true
console.log(!0);          // true

Negation toggles a boolean. If it is not a boolean primitive (true or false) it evaluates the truthy value. An empty string is false and any other string is true. 0 is false and any non-zero number is true.

Okay, so we've touched on boolean equivalent, and now can examine a conditional expression, which is what a while or if statement require.

while (condition)

if (condition)

An expression is anything that returns a value.

a = b

is NOT an expression, because it doesn't return a value. It sets a variable so is a statement.

a === b

IS an expression since it returns true or false, which are both values. Making sense, so far? The following are also expressions:

b && !a
function () {}

and we can go on...

while (number) {}

is a valid conditional because number is a value, true. The statement could be seen as written,

while (true) {
    break; // added for safety in case this gets run

I'll leave you to mull this over.


Ah-ha! So numbers pull a kind of double-duty then?

Thank you!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.