0
Related to introduction to JavaScript .
in introduction to javascript course string chapter i receive a problem e.g. console.log(" hello ____ ?. ") in between " hello " and " ? " . how i write code to display output in single quotation mark by default message is written is double qoutation mark i have space between the text no edit available ... what i do ? .
2 Respostas
+ 2
Assuming you were asked to greet a person, given a name. There are two possible ways I knew so far, using regular string concatenation or string interpolation
(Fix for missing identifier - noted by PanicS)
let yourName = 'Bruce';
[ Regular string concatenation ]
console.log( "hello '" + yourName + "' ?" );
Notice carefully there is a single quote before ending double quote of "hello'" string to the left. And there is a single quote right after the beginning double quote of the "' ?" string to the right.
[ String interpolation ]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
console.log( `hello '${yourName}' ?` );
Notice how we use backticks rather than regular single/double quotes to wrap string content.
P.S. Please use relevant words in post tags. "no" does not relate to Javascript in any way.
https://code.sololearn.com/W3uiji9X28C1/?ref=app
(Edited)
+ 1
Ipang your both codes will throw syntax error:
wrong:
console.log("hello" '+yourName+' "?");
I just place quotes with some space so we can see better, error is because you placed 3 strings with nothing to concate it, pluses are part of string inside single quotes
right:
console.log("hello" + yourName + "?");
For template literals also
wrong:
console.log(`hello '${yourName}?`);
right:
console.log(`hello ${yourName}?`);
About Muhammad Umair question you probably need to change from
console.log("hello ?");
To
console.log('hello ?');
I don't know what is between hello and ?, but here double quotes are replaced with single.
Or you maybe need this?
console.log('hello' + '?'); or
console.log("hello" + 'something' + "?");
note that we can place both double and single
I tried to find this task but I didn't find it, it will be better if you would give as course name and lection number. If this is from some other site place link to it if you can