8/11 Questions '.'


#1

Soo i made this code for this 8th step :3

var num = true ;

while (num) {
console.log("iReally doubt this")
num = false;}

for (var i = 2; i>300; i+25) {
console.log(i);}

It worked but in the for part, it didn't display the i variable , it just showed "false" .
This is the outcome in the compiler :

iReally doubt this
false

I was hoping for it to print the i value each time until the goal is set. For example, i hoped the result would be something like this :

iReally doubt this
27
52
77
102
127
...(goes on until 302)

So can someone tell me how can i make this happen?:smile:


#2

Well, it most likely says "false" because you set it to false here.:smiley:


#3

As @ragezapper already mentioned what you see is the echo of this line:

num = false;

the console has this feature where the last value is echoed and the reason why this is the last value is because your for loops has some problems:

for (var i = 2; i>300; i+25) {

The condition is i>300 but you start with i=2 and 2 is not greater than 300 so the loop does not even start. Also if you fix this have a look at the last part of the for loop:

i+25

this just computes a value better make it change i by e.g. i+=25


#4

hey devninja, read the feedback from haxor and ragezapper and they are right, once code amended it works just fine when its tweaked...

for (var i = 2; i>300; i+25) {
    console.log(i);
    }
console.log("Grrr...code NOT working like I want it to...K. take a breath count to 10");

for (var i=1;  i<11; i++){
    console.log(i);}
    
var dipstick = true;

while(dipstick){
    console.log("Let me see. K. while I figure this equation out..you go check the oil");
    dipstick = false;}

var num = true;
while (num) {
console.log("K. let me think...On three...")
num = false;}


for (var i=1;  i<4; i++){
    console.log(i);}
console.log("Eureka moment of clarity");

// no e did'nt..OH yes, e did,,,he remembered to add in 'dem backticks b4 'n' afta 'is code b4 e posted to da forum....e's a learnin...slowly...not bad. not bad...nice but dim shudave kalld 'im Tim

Output:

Grrr...code NOT working like I want it to...K. take a breath count to 10
1
2
3
4
5
6
7
8
9
10
Let me see. K. while I figure this equation out..you go check the oil
K. let me think...On three...
1
2
3
Eureka moment of clarity
1
26
51
76
101
126
151
176
201
226
251
276
Ah, bisto! by jove ...

here's the tweaked code:

for (var i = 1; i<300; i+=25) {
   
    console.log(i);}
console.log("Ah, bisto! by jove ...");