0

Can some help me to fix this?

<!DOCTYPE html> <html> <title> Riymon Site </title> <head> <script> document.addEventListener('DOMContentLoaded', function() { document.querySelector('form').onsubmit = function () { const name = document.querySelector('#name').value; alert('Hello, ${name}!'); }; }); var fname = document.getElementById("name"); </script> </head> <body> <h1> atay</h1> <form> <input autofocus id="name" placeholder="Name" type="text"> <input type="submit"> </form> </body> The output should like be this after submit name If your name as Coder The output should be like this Hello Coder! Not like this ('Hello, ${name}!');

27th Jul 2023, 9:20 AM
Riymon
Riymon - avatar
2 Answers
+ 1
use backticks (` `) for template literals, not (' '). Otherwise it is just a regular string. alert(`Hello, ${name}!`);
27th Jul 2023, 11:07 AM
Bob_Li
Bob_Li - avatar
+ 1
Thanks
27th Jul 2023, 11:16 AM
Riymon
Riymon - avatar