{"id":256,"date":"2017-04-13T12:12:48","date_gmt":"2017-04-13T12:12:48","guid":{"rendered":"http:\/\/www.bartlettpublishing.com\/site\/?p=256"},"modified":"2017-04-17T06:33:45","modified_gmt":"2017-04-17T06:33:45","slug":"spring-2017-week-10-class-notes","status":"publish","type":"post","link":"https:\/\/www.bartlettpublishing.com\/site\/2017\/04\/13\/spring-2017-week-10-class-notes\/","title":{"rendered":"Spring 2017 &#8211; Week 10 Class Notes"},"content":{"rendered":"<p>Great week everyone! We only have five classes left!<\/p>\n<p><b>Programming<\/b><\/p>\n<p>First of all, if anyone needs to send a program via email, this is sometimes more difficult than it should be. Email programs tend to be wary of people attaching programs to emails. Therefore, to send one, you need to (a) rename the file so it doesn&#8217;t end in .js or .html. Just rename the file to .txt. Then (b) compress the file into a zip file (this can usually be done by right-clicking on the file).<\/p>\n<p>Now to this week. For those who missed it, this week we practiced using the programmable web &#8211; using URLs to fetch JSON files, parse them, and use their data in our own programs. Below are the two files we typed in:<\/p>\n<p><a href=\"http:\/\/www.bartlettpublishing.com\/site\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-12-at-12.06.09-AM.png\" target=\"_blank\"><img class=\"alignleft\" src=\"http:\/\/www.bartlettpublishing.com\/site\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-12-at-12.06.09-AM-300x142.png\" alt=\"\" width=\"150\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.bartlettpublishing.com\/site\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-12-at-12.06.26-AM.png\" target=\"_blank\"><img class=\"alignnone\" src=\"http:\/\/www.bartlettpublishing.com\/site\/wp-content\/uploads\/2017\/04\/Screen-Shot-2017-04-12-at-12.06.26-AM-300x183.png\" alt=\"\" width=\"150\"  \/><\/a><\/p>\n<p>What this code does is go to the EventElf website, get a JSON feed of an event, and pull down some of the information into a web page. The things we used are:<\/p>\n<ul>\n<li>XMLHttpRequest &#8211; this object allows us to make connections to other websites for data. \u00a0We have to use <strong>new<\/strong> to get a new copy of this object. \u00a0The <strong>onload<\/strong> property should be set to\u00a0a callback that will trigger when the data is finished loading, and then the actual data itself will be in the <strong>responseText<\/strong> property. \u00a0The <strong>open<\/strong> function tells the method (usually &#8220;GET&#8221; sometimes &#8220;POST&#8221;) and the URL to obtain. \u00a0Then, the <strong>send<\/strong> function actually makes the call.<\/li>\n<li>JSON.parse &#8211; the data retrieved from XMLHttpRequest is just a string. \u00a0JSON.parse will take the string and, if it is a JSON object, parse it into a JavaScript object.<\/li>\n<\/ul>\n<p>From there, we just use document.getElementById like we normally do.<\/p>\n<p>There are a huge number of things on the web accessible by JSON feeds in this way. \u00a0When you find one, you read the documentation, and it will tell you how to construct URLs to access their data, and what the data looks like. \u00a0This is known as the API. \u00a0Unfortuantely, a lot of APIs require you to\u00a0perform tasks to authenticate yourself and your program, which adds a lot of complexity to the task, especially for new programmers.<\/p>\n<p>We did not talk much about our web store system, but will get more into that next week.<\/p>\n<p>HOMEWORK FOR THIS WEEK:<\/p>\n<ol>\n<li>Work on your cart program<\/li>\n<li>Modify the program we typed in this week to display even more data about the event (the pieces of data you want to display are your choice). \u00a0The easiest way to see what data is available is to either log the parsed javascript object to your console, or just go to the feed URL in your browser to see what it is giving you.<\/li>\n<li>Alternatively, you can find another API to interface with. \u00a0I have been trouble finding an API that is all of\u00a0(a) easy to use, (b) works with your browser&#8217;s security, and (c) does not have any inappropriate content. \u00a0That is proving difficult \ud83d\ude42 \u00a0I will update this if I find one. \u00a0I found several joke APIs, but they often have both regular and inappropriate jokes. \u00a0I found a &#8220;cat facts&#8221; API, but it doesn&#8217;t work with your browser&#8217;s security. \u00a0Anyway, if you find one you want to use, feel free to do so!<\/li>\n<\/ol>\n<p><strong>Electronics<\/strong><\/p>\n<p>This week we went into further depth on inductors. \u00a0If you have not read chapter 22, you should do so. \u00a0The &#8220;apply&#8221; section at the end is this week&#8217;s homework. \u00a0I should have the next chapter out this weekend, but the homework will be for chapter 22, which is already there.  <b>UPDATE<\/b> &#8211; chapter has been updated on the site.<\/p>\n<p><strong>Calculus<\/strong><\/p>\n<p>This week we covered trig substitutions in more depth. \u00a0I am still working on plans for this week&#8217;s homework and next week&#8217;s lesson. \u00a0More information hopefully over the weekend.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Great week everyone! We only have five classes left! Programming First of all, if anyone needs to send a program via email, this is sometimes more difficult than it should be. Email programs tend to be wary of people attaching &hellip; <a href=\"https:\/\/www.bartlettpublishing.com\/site\/2017\/04\/13\/spring-2017-week-10-class-notes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/posts\/256"}],"collection":[{"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":7,"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/posts\/256\/revisions\/265"}],"wp:attachment":[{"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bartlettpublishing.com\/site\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}