Booleans, if-else

Hi, after finishing practical exerciseimage
i did it another way than in solutions sheet
here is my program
image
is my solution righht ?

I’m not there yet, but I may comeback to this forum for help, I am stuck on the quiz (18), I am trying to following the formula from the lesson, and I have even looked at the answer / solutions, however, my script keeps on coming up like the below with errors, anyone have any ideas?

you have to declale right answear first, before comparing is to your answer
like this :
let correct_answer = “your correct answear”;
if (answer == correct_answer) { …}

1 Like

Thanks, although, I’m still not sure what I am doing wrong here as I get the error when I move onto else

image

Hi @Andre_Mark,

Instead of clicking the “Enter” key after the “if” statement block, Hold the “SHIFT” and then click on “Enter” key. This will create a new block in the console and then you can enter the else block statement.

Hope this helps. :slight_smile:

1 Like

Tbh, I am new to coding, so I am fairly slow to pick things up, I have just about got to this stage, and I am trying to re-learn hexadecimal from school, as that’s what the parseInt is right?
24 confused me, so I had to look at the solution for guidance, but I’m still coming back with errors, see below

1 Like

Can someone tell me what is wrong with this? Very new to programming & very confused. Dont know the rules for why we have to structure things the way we do, or use the symbols we do. This is literally copy & paste from ivans answer sheet & it doesnt work. I couldnt get my own to work so i went into the answers to see where i went wrong. after redoing the entire script it didnt work. So i tried to use the answers script which also doesnt work. incredibly frustrated as i have no idea why the hell this is happening.

var passenger = 0;
var station1 = parseInt(prompt(“Station 1! How many people go on the
bus?”));
if (passenger + station1 >= 30) {
console.log(“The buss is full”, passenger + station1 - 30, “have to
walk.”);
passenger = 30;
}
else {
passenger += station1;
console.log(station1 + " passengers are going on the bus.");
}
var station2 = parseInt(prompt(“Station 2! How many people go on the
bus?”));
if (passenger + station2 >= 30) {
console.log(“The buss is full”, passenger + station2 - 30, “have to
walk.”);
passenger = 30;
}
else {
passenger += station2;
console.log(station2 + " passengers are going on the bus.");
}
var station3 = parseInt(prompt(“Station 3! How many people go on the
bus?”));
if (passenger + station3 >= 30) {
console.log(“The buss is full”, passenger + station3 - 30, “have to
walk.”);
passenger = 30;
}
else {
passenger += station3;
console.log(station3 + " passengers are going on the bus.");
}
console.log(“The bus has arrived with " + passenger + " people on
board!”);

just saw we are having the same problem. did you get word back from anyone on a solution to this? until then I am moving on.

No, I didn’t hear from anyone, I moved on also as I would be on this module for a month at this rate

I’m actually a bit stuck on 28, the first part with the prompts I get, and I think I have just finally understood parseInt after watching loads of tutorials and the hexadecimal system, but it’s the parts after that I’m stuck on, anyone been there done it?

Hi @Andre_Mark and @Avrg,

Two points to note-
One, such large functions and logic should not be used on the console. These should be written down on a IDE (Atom , visual code etc) and then run the same code in the browser. The chrome console is supposed to be used only for debugging and small statements.

Two,
The console gets confused between double quotes in the code compared to the single quote for strings. Thus, if you change all the string part code to single quotes, the console accepts it.

Here is the code that works fro me, i just changed the double quotes to single quotes.

var passenger = 0;
var station1 = parseInt(prompt('Station 1! How many people go on the bus?'));
if (passenger + station1 >= 30) {
console.log('The buss is full', passenger + station1 - 30, 'have to walk.');
passenger = 30;
}
else {
passenger += station1;
console.log(station1 + 'passengers are going on the bus.');
}
var station2 = parseInt(prompt('Station 2! How many people go on the bus?'));
if (passenger + station2 >= 30) {
console.log('The buss is full', passenger + station2 - 30, 'have to walk.');
passenger = 30;
}
else {
passenger += station2;
console.log(station2 +'passengers are going on the bus.');
}
var station3 = parseInt(prompt('Station 3! How many people go on the bus?'));
if (passenger + station3 >= 30) {
console.log('The buss is full', passenger + station3 - 30, 'have to walk.');
passenger = 30;
}
else {
passenger += station3;
console.log(station3 + " passengers are going on the bus.");
}
console.log('The bus has arrived with' + passenger + ' people on board!');

Hope this helps.

1 Like

Hi all! I was playing around with the console and decided to play around with If and Else. Below you will see that I’m not getting exactly what I’m looking for.

image

As you can see I put a = 200 and for some reason all of the statements were triggered. When a = 700, the final console.log statement wasn’t triggered at all. Can someone help please? Thank you!