1

I can’t find the problem with my simple code. The button shows, but the alert pop-up doesn’t show when I click on it.

What am I doing wrong?

<DOCTYPE! html>
<html>
<body>
<h1>This will be a test for Javascript</h1>
<button> onclick="myFunction()">I like it</button>
<script>
 function myFunction() {
 alert("are you sure?");
}
</script>
</body>
</html>

Screenshot

pnuts
59.8k11 gold badges93 silver badges141 bronze badges
asked Aug 24, 2017 at 3:11
6
  • 4
    You should include actual code in the question, rather than posting an image of it. Commented Aug 24, 2017 at 3:14
  • 2
    Turn off smart quotes in the editor you're using to program with. You have curly quotes in your HTML and Javascript, they don't work. It needs to be plain single quotes or double quotes. Commented Aug 24, 2017 at 3:16
  • From the look of it the problem is the use of actual quotes rather than quotation marks. That won't parse correctly. Commented Aug 24, 2017 at 3:16
  • 1
    debugging 101: browsers have a developer tools console - errors will be shown there, usually telling you exactly what you've done wrong Commented Aug 24, 2017 at 3:23
  • It seems to be "(smart quote) instead of ". Change it and check again. And open your browser's developer (usually <kbd>F12</kbd> and monitor the console tab. It will provide you some hints to correct your problem. When it comes to learning JavaScript, Browser console is your friend. Commented Aug 24, 2017 at 3:23

3 Answers 3

1

Problem in smart quotes. Use

"

quotes.

answered Aug 24, 2017 at 3:20
Sign up to request clarification or add additional context in comments.

Comments

0

<button onclick="ok()">Ok</button>
<script>
function ok() {
 alert("ok");
}
</script>

answered Aug 24, 2017 at 3:23

1 Comment

What he needs is JavaScript. Not jQuery
0
  1. Use "" not " in your code
  2. Try to write your js code before html "button" code.
  3. And try also to add a comma in the end of onclick script.
answered Aug 24, 2017 at 3:55

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.