Help with quiz

I’ve been stuck on this question forever, I’m never going to get it. Can someone please explain how to do this and how you use the information in this course to do this? I remember some number stuff, but it’s like written backwards or double in javaScript or something? -+ ==-- ?

I can’t explain why I used the code i did. I don’t understand any of this so i just keep throwing in answers. Can someone please explain this? How do i make my brain think like this?

Can you post the link to the quiz please?

I don’t know how to do that. When i tried that before it just shows a random question, not the one I got stuck on.

I can take the quiz and find the question you’re on though.

1 Like

Thank you. I’ll try to find it again and post here. I gave up and closed out of the lesson

1 Like

Hello @byte5723385929. One way to complete the task-printing series if odd numbers would be to use console.log at every line-this therefore prints everything you need.

  1. The first two-console.log(number) is correct, since number is 5, and therefore odd.

  2. The next odd number down from five is three, hence the (3) on the third line. What the question wants you to do is to print that value-3. How would you print a number to the console?

  3. The last line requires you to print the next odd number down from 3, which is 1. The first part console.log is correct, since it logs the result. The next part requires you to get the number 1 from the value of the variable number. Since number is 5, you need to subtract something from 5 to get 1-which is 4: 5-4=1. I assume, that 4 was not an option, and you need to therefore subtract multiple values. In this case, subtracting 5-3-1 gives 4, since 5-3=2 and 2-1=1.

In JavaScript, there are a few different types of operator: mathematical, comparison operators, and there are also others such as the assignment operators (=,etc) and the concatenation operator (+). The mathematical operators are as follows:

+ this adds two values
- this subtracts two values
* this multiplies two values
/ this divides 
% finds the remainder of dividing two values
+= adds the value on the right to the value on the left
-= subtracts the value on the right from the value on the left
*= multiplies the value on the right with the value on the left
/= divides the value on the value on the left with the value on the right
%= sets something equal to the remainder of dividing the value on the left
with the value on the right
++ adds one to the value on the left
-- subtracts one from the value on the left

To find out more about mathematical operators, this is a good read.
I hope this helps!

1 Like

Thank you for the reply. I understood (for once) what it wanted me to do…display 5, 3, 1on the console. What i don’t get is how to do that with the options…i should have included those in the screencap. I don’t understand this though:

If we already printed 5 and 3, why subtract 4 and not 2? Does the number reset to 5 each time?

Thank you for the reference on operators, I remember learning about them but i don’t see how it works now because I don’t understand what this code is doing besides subtracting numbers…in some weird way.

1 Like

If you are trying to log 1, since number is equal to 5, don’t you think you should log number -4? If that is not an option “subtract” 3 first from number to get 2, then “subtract” 1 again to get 1, hence number-3-1.

1 Like

The reason is that you never subtract anything from the numbers variable-you just print various numbers. In fact, since the variable is const, you can never reassign it.

const number = 5;//declares a variable with a value of 5
//since it is a const variable, it cannot be reassigned
console.log(number);//logs number-no change to the 'number' variable
console.log(3);//logs 3 to the console-no change to number
console.log(number-3-1);//logs the result of subtracting the value stored
//inside the number variable: 5 - 3 - 1. Since JS follows the order of
//operations, 5-3 is evaluated first, giving 2, then 2-1 is evaluated
//giving 1. There is still no change to the number variable.

I hope this helps!

1 Like

That’s what I thought, subtract 5 - 2 - 1 so would print 5, 3, 1?
Apparently it’s always 5 even after i subtract 3…so there’s this -3-1 thing? I really don’t get it

I’m not really sure what you’re trying to say, but are you asking why after “subtracting” 3 from number the value is still 5?
If so, it’s because:

  1. number is declared with const so it can’t be changed.
  2. You are not directly reassigning or changing number. All you are doing is referencing the value stored in that variable.

Also why would you subtract 2 and 1 from 5? That gives you 2, but they want 5, 3, and 1 logged.
Also this statement: console.log(number-3-1); first references the value from number(5), and subtracts 3 and 1 from it to get 1, which it then logs.

where does it get ‘number-no change’ ? wouldn’t it log 5?

Lol, @codeneutrino meant it will print 5, with no change to number.

1 Like

Thanks @h1lo! Yes, I meant it would log the value stored within number, which is 5.

1 Like

I don’t understand what i’m trying to say either…I thought i’d subtract 2 and 1 from 5 to get 3…but it’s always 5? I failed math in High school anyways, maybe that’s what i’m missing here.

Ok, seems you are a little confused.
Look at this code:

const number = 9;

Let’s say I wanted to print out 6:

const number = 9;
console.log(number- 3);

This references the value in number, which is 9, and logs that value - 3 which logs 6, because 9-3 is 6 right?
However when you go to log number it will still print out 9, because even though you are logging number - 3, you are not changing number in ANY way.

1 Like

@h1lo said it very well.

When you complete line three, what you should actually be doing is purely console.log(3). The value stored in number does not change, and is therefore still 5. So in order to get from 5 to 1-as 1 is the next odd number down from 3, you must subtract 4 from 5. If -4 is not an option, you can use other number combinations, such as 5-3-1:

5 - 3 = 2
2 - 1 = 1
1 Like

I’m always confused with JavaScript…and anything related to math or logic or whatever it is smart people use. This example makes sort of makes sense but I don’t understand anything. Sorry for taking up time.

1 Like

I’m totally lost. Sorry for taking up time.

No need to apologize. I would like you to keep trying JavaScript, but if it gets really hard it’s okay to step away and try something else. If you have pro, consider trying Python 3. The syntax there is easier to understand. Never bring yourself down for not understanding something other people can. For example, learning long division took me AGES, even though my peers had understood it the first day it was taught. I wish you luck on your coding journey! :slight_smile: Also, don’t forget google is your friend! Do not think you need to know or figure out everything at the start.

1 Like