Event Object Properties - DOM (help please)

I think i might be losing it…
if anyone could shed some light I would greatly appreciate it.

here’s the exercise and my code, follow by the official solution which i commented out.
Is there any reason why the code works when i comment out my solution and run supplied code but doesn’t work when i run mine?

they are IDENTICAL!!! (or am i missing something?)…

thanks

code:

let social = document.getElementById('social-media');
let share = document.getElementById('share-button');
let text = document.getElementById('text');


let sharePhoto = function(event) {
  event.target.style.display = 'none';
  text.innerHTML = 'You share the puppy in ' + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;


/*
let sharePhoto = function(event) {
  event.target.style.display = 'none';
  text.innerHTML = 'You share the puppy in ' + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;

Hey there,

Don’t despair! I highly (highly) suspect it might have to do with the formatting of quote marks '' especially if you have an international keyboard. If i copy this code into my compiler it throws an error for both because of the ‘’.

Hope this helps!

1 Like

Thanks Pita, i’ll try, although I never had this problem before…

Ok, tried many ’ / " solutions, nothing seems to work…

Hm, can you try sharing a screenshot?

This is unusual indeed.

@mtf Do you have any ideas as to why this is happening?

We’ll need a link to the exercise page to be able to assess the situation.

1 Like

The forums markdown renders quotation marks strangely when pasting code that doesn’t have it’s formatting protected by placing it between back ticks. I’ve edited the OP to preserve the original formatting, and now the quotation marks appear correctly.

1 Like

Ah thanks for that. Duly noted!

1 Like

@chip4370828685, is the code in your post the entirety of your code? If so, the problem may be as simple as not having the closing */ for your multi-line comment at the end.

This would run as expected:

let social = document.getElementById('social-media');
let share = document.getElementById('share-button');
let text = document.getElementById('text');

/*
let sharePhoto = function(event) {
  event.target.style.display = 'none';
  text.innerHTML = 'You share the puppy in ' + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;
*/


let sharePhoto = function(event) {
  event.target.style.display = 'none';
  text.innerHTML = 'You share the puppy in ' + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;

The code below, however, will throw a syntax error:

let social = document.getElementById('social-media');
let share = document.getElementById('share-button');
let text = document.getElementById('text');


let sharePhoto = function(event) {
  event.target.style.display = 'none';
  text.innerHTML = 'You share the puppy in ' + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;


/*
let sharePhoto = function(event) {
  event.target.style.display = 'none';
  text.innerHTML = 'You share the puppy in ' + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;

If you open your browser’s console, and click Run with the code in the second example, you’ll see the following error message:
Uncaught SyntaxError: unterminated comment

For reference, the exercise is found here.

:man_facepalming:t4:

That WAS indeed the problem. Thank you all!

1 Like