-1

I want a javascript alert that reads, "It's "Hammer" time!"

What is the best code to write this?

  • 5
    A simple googling would solve your problem. Why waste a question on this? – Krishna Prashatt Jun 06 '18 at 09:45
  • 2
    What have you tried? Some basic research on "javascript alerts" and "escaping characters" would have explained how to do this. – Lewis Jun 06 '18 at 09:46
  • or alternatively `alert('"It\'s "Hammer" time!"');`, or use template literals. But seriously, you could have researched this in less time than it took to write the question – ADyson Jun 06 '18 at 09:48

5 Answers5

4

Although you could use a string with ' and escape the ', or a string with " and escape the "s, it would be better to use a template literal, which doesn't require escaping of quotes because its delimiter is the backtick:

alert(`"It's "Hammer" time!"`);
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
1

For displaying single or double quotes, you can write your code like this alert("\"It's \"Hammer\" time!\"")

Raylian
  • 163
  • 4
0

Escape the "s other than the ones from the begining and ending..

alert("\"It's \"Hammer\" time!\"")
Ashish Ranjan
  • 12,760
  • 5
  • 27
  • 51
0

You need to escape it using \

For example:

alert("Something \"here\"!!");
Tiago Mussi
  • 801
  • 3
  • 13
  • 20
0

How to display double quotes in JavaScript

Or use string interpolation, where you can have both without escaping.

alert(`Hello, I'm "nobody"!`);
Ravenous
  • 1,112
  • 11
  • 25
  • Why the downvote? Is it cause I answered a bad question and support lazy people? Or cause I called it "string interpolation", and not "template literal"? – Ravenous Jun 06 '18 at 10:00