var name = 'hammou';
var letter= console.log(name[0]);
now i wnat to know is the first letter is "H" or not
if(letter == "h")
{
console.log('your name started by "H"');
}
else
{
console.log('your name does not started by "H"');
}
CodePudding user response:
var name = 'hammou';
var letter= name[0];
if(letter == "h")
{
console.log('your name started by "H"');
}
else
{
console.log('your name does not started by "H"');
}
you cant insert "console.log(name[0])" inside variable because "console.log" is to write in console you can just insert "name[0]" inside the variable
CodePudding user response:
You don't need to use console.log()
use directly the variable like:
var name = 'hammou';
var letter= name[0];
if(letter == "h")
{
console.log('your name started by "H"');
}
else
{
console.log('your name does not started by "H"');
}
CodePudding user response:
I'm not sure what you are trying to achieve, but you don't have to log your code to store it in a variable. I would suggest you to use the charAt function to get the first value of a string and see variables for further information on how to assign values to variables.