11/11 Review Half day for find solution, i give up


#1

Good day, my first question, I waste half day for find what im doing wrong, Can somone explain where is the problem? This "Do/while" isnt working as i wish. Had no idea why.

//type your code here
var city = "Maikop"
for (var i=1; i<2; i++) {
    console.log("Moving ")
} 
do { 
    console.log("from " + city);
} while (city) {
    city="Bila Tserkva";
}
console.log("to " + city + "!!!");

Problem Solved.

strange, changed var city = 0; and it works, so, "While" teh isn't work with strings?

var city = 0;
    for (var i=1; i<2; i++); {
    console.log("Moving ");
};
do { 
    console.log("from ");
} while (city) {
    city=1;
}
console.log("to " + city + "!!!");

#3

do {
console.log("from " + city);
city="Bila Tserkva";
} while (city === Maikop)


#4

Maybe you should have a look at this post:

From what I can see your do/while loop has 2 problems. The first is that you seem to expect that this part (commented part) belongs to the loop:

    do { 
        console.log("from " + city);
    } while (city) /*{
        city="Bila Tserkva";
    }*/

which it does not. This part is in no way connected to the loop the {} are just unncessary here and it is just regular code that is executed after the loop is done. And the other "problem" is that you use values as conditions of course if you know from e.g. this site:

http://www.sitepoint.com/javascript-truthy-falsy/

what value is translated to what boolean this might be ok, but in the end it's not that obvious that all strings that are not empty are treated as true aso so better use what @jchase0487 suggested and compare it to an acutal value this should make it easier to understand by a reader or your later self and it is also safer than relying on this sideeffects. But if you do use === "Maikop" as it would be treated as a variable if you omit the "".