I am new to React and I was practicing this code but for some reason, the variable that I used in the code i.e., name and count doesn’t seem to work. Kindda sure that if I have to print the name using console.log then I have to write it like —–console.log(‘Hello $(name)’);—–. I have done the same thing with name and count but they are being printed as text instead of variable.
Expected output:
John you have clicked me 2 time/s.
Actual output:
${name} you have clicked me ${count} time/s.
Please tell me how do i Fix this
function Button() {
let count = 0;
const handleClick = (name) => {
if (count < 3) {
count++;
console.log('${name} you have clicked me ${count} time/s.');
} else {
console.log('${name} stop clicking me!');
}
};
return <button onClick={() => handleClick('John')}>Click Me</button>;
}
export default Button;