Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

why is it not working

<button onclick="" myFunction(); >save</button>

<a href="#" id="myid"></a>

<script> function myFunction();{

var email = prompt("whats your email"); document.getElementById("myid").href = "mailto:" + email + "?subject=Cabbages";

}

</script>

1 Answer

To get what you have to work you need to put the function inside the onclick attributes quotations for your button. Then you need to remove the semicolon from your function declaration:

<button onclick="myFunction();">save</button>
<a href="#" id="myid">link</a>

<script> 
function myFunction(){
  var email = prompt("whats your email"); 
  document.getElementById("myid").href = "mailto:" + email + "?subject=Cabbages";
}
</script>

Also, it's probably a good idea to put something between your anchor tags so that it shows on the page.