-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
  • 313,535
  • 40
  • 245
  • 254
1

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

Raylian
  • 129
  • 4
0

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

alert("\"It's \"Hammer\" time!\"")
Ashish Ranjan
  • 12,196
  • 5
  • 26
  • 47
0

You need to escape it using \

For example:

alert("Something \"here\"!!");
Tiago Mussi
  • 799
  • 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,111
  • 10
  • 23
  • 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