Not sure what is going on…
After creating the vars below, it is asking to print the values on the console…
var favoriteFood = ‘pizza’;
var numOfSlices = 8;
we did the above, but it keeps telling me it is wrong…
What did I miss? Thx
UPDATE:
I got it!!!
console.log it is NOT in camel form! For that reason, console.log shouldn’t have the second word started with capital as I wrote initially… now that bamboozled my head a bit…
If I type var numOfSlices = number(8) the checkmark on the left with the instructions takes it as a correct answer but on the right side the “terminal” says there’s a syntax error.
I saw the hint and it says to declare the variable using this way var newNum but how do I assign the name of the variable using this?
I’ve seen that most of the answers are var numOfSlices = 8
So I’m confused, why does the checkmark takes it as a good answer if there is a syntax error, when do I use the var newNum and how do I name it.
assigns the value 8 to the variable, numberOfSlices.
We wouldn’t normally use the Number constructor on number literals. Instead it is usually applied when it is given a string value or some expression that can be coerced to a number literal.
This description on variables in the link below really helped me understand the bigger picture, It’s particularly useful if you are a “visual” learner. Thought I’d share. Cheers!
At this point of learning JS the background reasoning is rather esoteric. For the time being it is best to follow good practice and always declare variables.
var a; // a is declared but not defined
var a = 42 // a is declared and initialized (defined)
a = 42 // a is defined but not declared
The latter can be deleted, while the others cannot.
As you progress through the course you will learn about functions and scope, so we won’t bring that up just now.
a = 42
console.log(a) // 42
delete a
console.log(a) // ReferenceError: a is not defined
var a = 42
console.log(a) // 42
delete a
console.log(a) // 42
let a = 42
console.log(a) // 42
delete a
console.log(a) // 42
const a = 42
console.log(a) // 42
delete a
console.log(a) // 42
As we can see, declared variables are persistent, and delete has no effect. The last one above is not just persistent but immutable. Its value cannot be changed.
İkinci dersin ikinci alıştırmasını birinci alıştırma gibi kodlamaya çalıştım, fakat hata veriyor. Verdiği hata ise şu; Did you create a variable named numOfSlices ? yani numOFSlices adında bir değişken oluşturup oluşturmadığımı soruyor. Rica etsem yardımcı olur musunuz?
Bu da benim kodlamam ama sistem bunu kabul etmiyor, mutlaka bir hatam söz konusu fakat bunu bilmiyorum, eğer biliyorsanız lütfen söyleyin. Teşekkürler.
var numOFSlices = 8;
console.log(numOFSlices);
//Output:8