Should it not have been y for the answer? This is the second in a row I got wrong and they were both the same type of questions.
Can any one explain why my answer is wrong. I must be missing something.
That seems off to me.
I’ve read this a dozen times, maybe I am not cut out for programming if this stumps me.
It says in the image attached
QUOTE" When print (x) runs it looks inside the variable called x and prints out the value its holding. In this case, the variable x is holding the value 5 (not from what i see it is holding y) so that is what gets printed out."
var y = 5;
var x = y;
if print(x) is called is this not asking to know what is in var x? why the heck would it print 5 if it is holding y?
Once you get past the learning curve, it’ll come naturally. It’s like learning a new language. x = 5; because y is given the value of 5 and then x is given the value of y (5). One way to look at this is: x = y = 5
Both x and y are variables that store certain data (numbers, strings, etc.), but if a variable(x) tries to store another variable(y), then the variable(x) copies the value(5) of the other variable (y).
This allows you to change the value in y while keeping the original value in x in case you ever want to go back to it. Such as:
var y = 5;
var x = y;
y = y + 2;
print(y); //y = 7
print(x); //x = 5
Hope this did a better job, but feel free to reply if otherwise!
This sounds like a case where a drawing or even a video of the traditional post office box analogy (one labeled x, and another labelled y, with pieces of paper showing a 5 – except you can’t remove the paper from the box, just copy it) might be helpful.
A better way to explain it is to look at the datatype of x’s value. var y = 5;
This line creates a variable called y and assigns it a value of 5. var x = y;
This line creates a variable called x assigns it a value of y. Since y is not a string, x is not equal to 'y'. The only way y could be the value is with a string, which would require 'y'. Therefore, x gets assigned the value 5. print(x);
This prints out the variable x, which is assigned the value 5.