https://www.freecodecamp.com/challenges/get-geolocation-data
Go through the challenge and do:
$('#data').html(...) and it will fail.
change to $("#data").html(...) and change nothing else, and it will work.
Many js developers prefer to use single-quotes in js and double quotes in html. Additionally, the other jquery challenges do not have this bug.
<script>
// Only change code below this line.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
$('#data').html('latitude: ' + position.coords.latitude + '<br>longitude: ' + position.coords.longitude);
});
}
// Only change code above this line.
</script>
<div id = "data">
<h4>You are here:</h4>
</div>
The description does mention this:
Don't forget to use double quotes around selectors as mentioned here.
There are some inconsistencies as to how much this is enforced. One of the early jQuery challenges actually has a test that is looking specifically for single quotes to make sure you're not using them.
I also prefer using single quotes in Javascript myself, but as it is mentioned in the description, I'm not sure whether it's worth fixing/fixable.
Over the past while contributing to FreeCodeCamp, I have found out that it is impossible to make perfect tests. We can only aim to get as close as possible. Letting go of enforcing double quotes here means that a faulty selector (for example, $('data")) would pass, no matter how hard we try to get the tests perfect.
@FreeCodeCamp/moderators What's your input on this? I'm especially concerned about it not being consistent. Some challenges use a . to allow for any character in the place of the ", some enforce the "
Using the regex /(['"])data\1/ it is possible to allow any _matching_ quotation.
This will match "data" and 'data' but not "data' or 'data".
I think it would be worth switching all the challenges to that if it works
as single-quote usage seemed like the standard. I guess I was wrong but now
I'm curious what the percentage is, how many devs use single quote vs
double quote?
On Fri, Nov 18, 2016 at 11:14 PM Abhisek Pattnaik [email protected]
wrote:
Using the regex /(['"])data\1/ it is possible to allow any quotation.
This will match "data" and 'data' but not "data' or 'data".—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/11704#issuecomment-261555282,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOKKP5dXXSsmPWJ8-FF_wDVBZSZlB7mTks5q_cDggaJpZM4K2VcP
.
I think it would be worth switching all the challenges to that if it works
as single-quote usage seemed like the standard. I guess I was wrong but now
I'm curious what the percentage is, how many devs use single quote vs
double quote?
We should simply allow both the ' and ", and restrain from debating the standard and best practices, which is beyond scope of any challenge on FCC unless specified for the challenge.
I like @abhisekp suggestion and we should update the test cases to have the regex mentioned.
Wow, thank you @abhisekp, I did not know about that! That is pretty amazing ✨
A PR resolving this issue should probably also get rid of this test. It quotes a jQuery style guide, which I have not been able to find.
The entirety of the jQuery challenges seed has to be updated, as well as some of the JSON API's and AJAX seed
@systimotic I believe the style guide they are referencing is this: http://contribute.jquery.org/style-guide/js/#quotes
But yes, I agree we should drop the requirement as it's not a hard rule.
I would like to work on this. Do we know which challenges need to be updated?