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

Please,someone, explain this very short line of code

<input aria-checked="false">
<script>
const input = document.querySelector('input')
let isChecked = JSON.parse(setAttribute('aria-checked',!isChecked))
.....
..............
..
//Please explain what JSON.parse does
</script>

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

JSON parse is a method used to format the JSON information retrieved into something that JavaScript can recognise. :-)

Please help me. I wan to scroll to blueDiv without using scrollTo because I do not think it will look good on mobile. Is there a better way to scroll to blueDiv when I clicked the button.

 <!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
*{margin:0;}
html{scroll-benhavior:smooth;}
</style>
</head>
<body>
<div class="blackDiv" style="height:100vh;width:100vw;position:relative;background:#000;">
<button style="position:absolute;bottom:0;width:100%;padding:15px 16px;">Click me to Scroll to blue div</button>
</div>
 <div class="blueDiv" style="height:100vh;width:100vw;background:#0a67ba;"></div>

 <div class="whiteDiv" style="height:100vh;background:transparent;"></div>
<script>

let button = document.querySelector('button')
let blueDiv = document.querySelector('.blueDiv')
window.addEventListener('click',function(e){
if(e.target.tagName === 'BUTTON' ){
window.scrollTo(0, 1290)
}
})
</script>
</body>
</html>