I am completely stuck

var salary = prompt(“What is your income this month?”);

if(salary<1000){console.log(“your tax is ${salary*0.1}”)}

else if(salary>=1000) {console.log(“your tax is ${((salary-1000)0.3)+(10000.1))}”)}

Here ${} does not do the calculation in the string like I am expecting

var salary = prompt(“What is your income this month?”);

if(salary<1000){console.log("your tax is " + salary*0.1)}

else if(salary>=1000) {console.log("your tax is " + (((salary-1000)0.3)+(10000.1)))}

is working, but I need to know why the other two wasn’t working

1 Like

Hey @Louwrens, hope you are great.
Here is the first code but fixed, you have some syntax errors.

//var salary = prompt("What is your income this month?");
//variable tax should be VAR so it can be public
if(salary<1000){var tax = salary*0.1}
//variable tax should be VAR so it can be public
else {
  //the entire result should be closed in ()
  var tax = (
    //here you miss the multiplier
  ((salary-1000)*0.3) + (10000.1) 
)}
//you miss a comma or + sign between each element
console.log("your tax is ", tax)

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

Hi all, I am currently struggling with Exercise 24 in the lesson “Practice Exercise - Booleans & If, Else statements”.

I have approached the task like this:
var capacity = 30;

var station1 = prompt(“Station 1! How many people go on the bus?”)

if (capacity < station1) {
console.log(“The bus is full”, +(station1-capacity) + “have to walk”); }
else {
console.log(station1); }
14

This has worked so far, producing 14 as expected, however, when I add station 2 to this, I get the answer “The bus is full 1383 have to walk” instead of the expected “13”, that I entered in the prompt:

var station2 = prompt(“Station 2! How many people go on the bus?”);

if (capacity < (station1 + station2)) { console.log(“The bus is full”, +((station1 + station2)-capacity) + “have to walk”); }
else {
console.log(station2); }

My “plan” was to receive 13 as the output, and add station3 in the same manner I added station2 in the next step. I had a brief look at the solution, which was approached in a different manner, but I believe my approach can still work. Can anyone point out what error I made? I recognised hat the issue arises when station1 and station2 are added up in the parentheses, but it isn’t quite clear to me why the correct addition doesn’t occur. Thank you very much for any help with this!

thanks yes I understand. I see it’s mostly syntax, will improve with some exercises.

Hi all, apologies for posting again, but I am still struggling with Exercise 24 in the lesson “Practice Exercise - Booleans & If, Else statements”.

I have approached the task like this:
var capacity = 30;

var station1 = prompt(“Station 1! How many people go on the bus?”)

if (capacity < station1) {
console.log(“The bus is full”, +(station1-capacity) + “have to walk”); }
else {
console.log(station1); }
14

This has worked so far, producing 14 as expected, however, when I add station 2 to this, I get the answer “The bus is full 1383 have to walk” instead of the expected “13”, that I entered in the prompt:

var station2 = prompt(“Station 2! How many people go on the bus?”);

if (capacity < (station1 + station2)) { console.log(“The bus is full”, +((station1 + station2)-capacity) + “have to walk”); }
else {
console.log(station2); }

My “plan” was to receive 13 as the output, and add station3 in the same manner I added station2 in the next step. I had a brief look at the solution, which was approached in a different manner, but I believe my approach can still work. Can anyone point out what error I made? I recognised hat the issue arises when station1 and station2 are added up in the parentheses, but it isn’t quite clear to me why the correct addition doesn’t occur. Thank you very much for any help with this!

Hello, I’m having an issue with the practice assignment called "Practice Exercises: Console.log and Variables.
Question 8 asks us to do text formatting for the width and length of two floating point variables. I tried typing in exactly the answer given in the cheatsheet but all i get is an error back. I dont know what the expected output is supposed to be, and whatever Im typing into google to figure it out is bringing me off track.
Solution given:

var length = 10.101;
var width = 3.843;
console.log(The rectangle is ${length} cm long and ${width} cm wide.);

All it does though is print out “The rectangle is ${length} cm long and ${width} cm wide.”

Thanks in advance!

1 Like

In the CONSOLE reading assignment, it mentioned saving your work. I am completely new to this area (and completely fascinated!). I could not find a menu option in the area that allowed me to save my work. Is there an option to do so? If not how do seasoned dev’s do it?

1 Like

I think you should just show the length and width in the console msg.

so your code should be

var length = 10.101;
var width = 3.843;
console.log(`The rectangle is ${length} cm long and ${width} cm wide.`);

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

your code files should be saved on the format type that is refer to (if your code is a HTML type, save the file with format type .html at the end of the name for the file fileName.html, for Javascript code is .js fileName.js)

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Thanks for your reply brotha it helped

1 Like

Hi everyone, I am at Booleans and if else statements exercise 21. Height.
For some reason syntax error says else is an unexpected token and I just don’t understand why. I checked solutions and it’s basically written the same. Can someone please take the time and have a look at this?

var userH = prompt(“Whats your height?”); if(userH>190){ alert(“You are tall!”);} ; else if(userH<150){alert(“you are tiny”) else{ alert(“You are avargae”);}

I tried all sorts of variants. I tried console.log. I tried with and without semi-colons in between. I just don’t seem to get it right.

1 Like

This is an example in the book. I cant figure out why this returns 8 instead of just returning 1 like it says in the first if statement. I get the whole recursion, to step the exponent down and multiply the base up. But the final thing it does would be to return 1, would it not?

function power(base, exponent) {
if (exponent == 0) {
return 1;
} else {
return base * power(base, exponent - 1);
}
}
console.log(power(2, 3));
// → 8

1 Like

Hey @Karla, hope you are well.

You have miss type on your syntax, here is the same code fixed:

var userH = prompt("Whats your height?");
if (userH > 190) {
  alert("You are tall!");
} else if (userH < 150) {
  alert("you are tiny");
} else {
  alert("You are avargae");
}

Your else is inside the else if body (inside the {}) also you have a ; at the start of the else if

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like
function power(base, exponent) {
//only will trigger if exponent is equal to zero
  if (exponent == 0) {
    return 1; //when 'if' condition is valid, return this.
  } else { 
    //Ex: 2 * (2*2) = 8, 
    return base * power(base, exponent - 1); 
  }
}
console.log(power(2, 3));
// → 8

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

Thank you @thecil.
Silly mistake, but now I see what was wrong. Thanks again :+1:

1 Like

Hi there, I am stuck with the extension install in visual studio. I cant sync the extension, I manage to get the token, not sure how because the way the install video showed was not work for me. I do not know how to get Gist ID. I keep having Sync: invalid Gist ID. Where I get this? How can I put the token manually? Many thankssss

1 Like

Hey @Raquel, hope you are well.

I do not understand quite well your problem, which course lesson are you referring to? (i guess is React right?)

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hi, i’ve tried to solve this, but i just can’t seem to get what I’m doing wrong here. Why can’t I input 10 in prompt 1, 10 in prompt 2 and 2 in prompt 3 without getting “buss is full”?

It seems like it adds up the number horizontally. Like if i write 1 in prompt 1 and 1 in prompt 2, the message automatically turns to “buss is full”. How come?

var busstop1 = prompt (“How many passengers are on the bus?”);
if (busstop1 < 30) {
console.log ("This many people went on stop one: ", (busstop1));
}
else {
console.log (“Buss is full”);
}
var busstop2 = prompt ("How many passenger are on stop 2? ");
if (busstop2 + busstop1 < 30) {
console.log ("This many people went on to stop two: ", (busstop2));
}
else {
console.log (“Buss is full”);
}
var busstop3 = prompt (“How many passenger are on stop 3?”);
if (busstop1 + busstop2 + busstop3 < 30) {
console.log ("There are: ", busstop1 + busstop2 + busstop3 - 30, “seats left”);
} else console.log ("The buss is full! ");

I installed node,js, I even tried changing this folder to one located on the same hard disc as where node.js was installed. but it seems I am missing something.