Getting this error
This is the code. I've tried this in vscode as well and prettier starts giving another error in my var humanAge and says it needs a wtf.
3 Replies
missing a + in the string interpolation
after humanage variable reference
also unsure how the * next to a number is treated 🤔
should just be multiplication
this is part of the pain of concatenating strings, it's really easy to miss a
+
sign. You should have a +
after humanAge
, so humanAge + " human ...
It's typically easier to use template literals, a fancy name for a really simple syntax.
Say I want to let a user enter a name, then I output hello, followed by their name. I could do this;
But I have to make sure I add in the space at the end of the string, and the plus sign.
It's easier to use template literals, instead of a "
or '
for the string, use a backtick ` (it's to the left of the 1
key)
Template literals use this ${contentHere}
syntax, you can put any code in there you could put in a function argument
You can do fun stuff like ternary operations, string manipulation, etc.
Pretty much, you can put anything in there so long as it resolves to a single value, so IIFEs are valid, but for
loops are not.
MDN docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
James Q Quick on Template Literals: https://youtu.be/O4DaRScJFNs?t=19