# A couple of newbie questions about JavaScript [return in switch]

Hi!

A week ago my math teacher challenged me to write a script that would determine between which 10-logarithms a number is positioned. Challenge accepted:cool:

I did not find this very hard, so I wanted to see if I could make it a little better! This is what it looks like for the moment:

``````var var0 = Math.pow(10,0);
var var1 = Math.pow(10,1);
var var2 = Math.pow(10,2);
var var3 = Math.pow(10,3);
var var4 = Math.pow(10,4);
var var5 = Math.pow(10,5);
var var6 = Math.pow(10,6);
var var7 = Math.pow(10,7);
var var8 = Math.pow(10,8);
var var9 = Math.pow(10,9);
var var10 = Math.pow(10,10);

var tioPotenser = [var0, var1, var2, var3, var4, var5, var6, var7, var8, var9, var10];

var userAnswer = parseInt(prompt("Please enter the number you would like to find out between what "));

for(var i = 0; tioPotenser.length; i++) {
console.log("Ditt tal ligger mellan tiopotensen" + " " + var0 + " " + "och" + " " + var1);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var1 + " " + "och" + " " + var2);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var2 + " " + "och" + " " + var3);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var3 + " " + "och" + " " + var4);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var4 + " " + "och" + " " + var5);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var5 + " " + "och" + " " + var6);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var6 + " " + "och" + " " + var7);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var7 + " " + "och" + " " + var8);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var8 + " " + "och" + " " + var9);
console.log("Ditt tal ligger mellan tiopotensen" + " " + var9 + " " + "och" + " " + var10);
} else {
console.log("Antingen har du inte skrivit in ett tal, eller sĂĄ har du skrivit in ett tal som Ă¤r stĂ¶rre Ă¤n 10 000 000 000");
}
};

case 0var:
if(Math.pow(10,0) <= 0var && 0var < Math.pow(10, 1/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^(1/2) men stĂ¶rre Ă¤n eller lika med 10^0");
} else if(Math.pow(10, 1/2) <= 0var && 0var < Math.pow(10,1)) {
console.log("och det Ă¤r mindre Ă¤n 10^1 men stĂ¶rre Ă¤n eller lika med 10^(1/2)");
};
break;

case 1var:
if(Math.pow(10,1) <= 1var && 1var < Math.pow(10, 3/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^1,5 men stĂ¶rre Ă¤n eller lika med 10^1");
} else if(Math.pow(10, 3/2) <= 1var && 1var < Math.pow(10,2)) {
console.log("och det Ă¤r mindre Ă¤n 10^2 men stĂ¶rre Ă¤n eller lika med 10^1,5");
};
break;

case 2var:
if(Math.pow(10,2) <= 2var && 2var < Math.pow(10, 5/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^2,5 men stĂ¶rre Ă¤n eller lika med 10^2");
} else if(Math.pow(10, 5/2) <= 2var && 2var < Math.pow(10,3)) {
console.log("och det Ă¤r mindre Ă¤n 10^3 men stĂ¶rre Ă¤n eller lika med 10^2,5");
};
break;

case 3var:
if(Math.pow(10,3) <= 3var && 3var < Math.pow(10, 7/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^3,5 men stĂ¶rre Ă¤n eller lika med 10^3");
} else if(Math.pow(10, 7/2) <= 2var && 2var < Math.pow(10,4)) {
console.log("och det Ă¤r mindre Ă¤n 10^4 men stĂ¶rre Ă¤n eller lika med 10^3,5");
};
break;

case 4var:
if(Math.pow(10,4) <= 4var && 4var < Math.pow(10, 9/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^4,5 men stĂ¶rre Ă¤n eller lika med 10^4");
} else if(Math.pow(10, 9/2) <= 2var && 2var < Math.pow(10,5)) {
console.log("och det Ă¤r mindre Ă¤n 10^5 men stĂ¶rre Ă¤n eller lika med 10^4,5");
};
break;

case 5var:
if(Math.pow(10,5) <= 5var && 5var < Math.pow(10, 11/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^5,5 men stĂ¶rre Ă¤n eller lika med 10^5");
} else if(Math.pow(10, 11/2) <= 2var && 2var < Math.pow(10,6)) {
console.log("och det Ă¤r mindre Ă¤n 10^6 men stĂ¶rre Ă¤n eller lika med 10^5,5");
};
break;

case 6var:
if(Math.pow(10,6) <= 6var && 6var < Math.pow(10, 13/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^6,5 men stĂ¶rre Ă¤n eller lika med 10^6");
} else if(Math.pow(10, 13/2) <= 2var && 2var < Math.pow(10,7)) {
console.log("och det Ă¤r mindre Ă¤n 10^7 men stĂ¶rre Ă¤n eller lika med 10^6,5");
};
break;

case 7var:
if(Math.pow(10,7) <= 7var && 7var < Math.pow(10, 15/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^7,5 men stĂ¶rre Ă¤n eller lika med 10^7");
} else if(Math.pow(10, 15/2) <= 7var && 7var < Math.pow(10,8)) {
console.log("och det Ă¤r mindre Ă¤n 10^8 men stĂ¶rre Ă¤n eller lika med 10^7,5");
};
break;

case 8var:
if(Math.pow(10,8) <= 8var && 8var < Math.pow(10, 17/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^8,5 men stĂ¶rre Ă¤n eller lika med 10^8");
} else if(Math.pow(10, 17/2) <= 2var && 2var < Math.pow(10,9)) {
console.log("och det Ă¤r mindre Ă¤n 10^9 men stĂ¶rre Ă¤n eller lika med 10^8,5");
};
break;

case 9var:
if(Math.pow(10,9) <= 9var && 9var < Math.pow(10, 19/2)) {
console.log("och det Ă¤r mindre Ă¤n 10^9,5 men stĂ¶rre Ă¤n eller lika med 10^9");
} else if(Math.pow(10, 19/2) <= 2var && 2var < Math.pow(10,10)) {
console.log("och det Ă¤r mindre Ă¤n 10^10 men stĂ¶rre Ă¤n eller lika med 10^9,5");
};
break;

default:
console.log("Om du kan fĂĄ det hĂ¤r att skrivas ut har det hĂ¤nt nĂĄgot ovĂ¤ntat");
};
``````

Now to the question:

`````` if (var0 <= userAnswer && userAnswer < var1); {
console.log("Ditt tal ligger mellan tiopotensen" + " " + var0 + " " + "och" + " " + var1);
``````

If the if-statement is true, I would like the console.log-statement to be printed out, and I would also want the variable userAnswer to a new name, 0var.

When this is done, I want this to run through a switch statement and if the case would be 0var, I would like this to happen:

``````switch(userAnswer) {
case 0var:
if(Math.pow(10,0) <= 0var && 0var < Math.pow(10, 1/2)) {
console.log("and it's smaller then 10^(1/2) but bigger then or equal to 10^0");
} else if(Math.pow(10, 1/2) <= 0var && 0var < Math.pow(10,1)) {
console.log("and it's smaller then 10^1 but bigger then or equal to  10^(1/2)");
};
break;
``````

However, when I try to run this, I get errors. It has something to do with the â€śreturnâ€ť - am I miss-using it? What should I do to make the code do what I have described?

Sorry if this wasnâ€™t written in very good English, itâ€™s not my native language:)