Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. # JavaScript
  2.  
  3. Hi Student!
  4.  
  5. First, your code looks nice and clean. You're looping through the prizes array, and then setting an "onclick" function for each button. In the function, you correctly alert the btnNum index of the prizes array. Good work on all that!
  6.  
  7. The problem here is with the "scope" of btnNum. You're using the "var" keyword to create btnNum, which we generally use because it creates nice global variables which can be accessed almost anywhere.
  8.  
  9. However, the onclick function is not actually run *until the button is clicked*. By that point, the global btnNum has done its job counting from 0 to prizes.length, and it will retain that value until modified further.
  10.  
  11. What we need in this case is a btnNum which is limited in scope to your "for" block. This used to be a fairly tricky thing to do, but we now have a special keyword "let" for exactly these situations.
  12.  
  13. **If you change your "var btnNum" to "let btnNum", the variable will be created the same but exist only within the block.**
  14.  
  15. Conveniently, javascript also assumes that because btnNum is now scoped to this block, we want prizes[btnNum] to be calculated the first time through instead of when the button is clicked.
  16.  
  17. Variable scope can be tricky, even I still need a quick refresher in it every now and then. :)
  18.  
  19. Let me know if I've answered your question! I'm happy to go into more or less detail if you'd like.
  20.  
  21. Thanks,
  22. Anthony
  23.  
  24. # Rails
  25.  
  26. Hi Student!
  27.  
  28. Congrats on beginning to grasp associations. As I'm sure you've found, associations can really improve our data models, making things easier to read and more efficient. :through is a great example of both, although it can be confusing at first.
  29.  
  30. Whether you're using has_one or has_many, :through operates the same, as a way of connecting two models through a third.
  31.  
  32. Imagine we have three data models: Doctor, Patient, and Appointment.
  33.  
  34. We might think of our associations like this:
  35.  
  36. > Doctor has_many :appointments
  37.  
  38. > Patient has_many :appointments
  39.  
  40. > Appointment belongs_to :doctor and belongs_to :patient (it has one of each)
  41.  
  42. Its easy to see in this case where we might want a relationship between doctors and patients: How many doctors does a certain patient have? Which patients have seen the most doctors?
  43.  
  44. To make those connections, we need to use the appointments model. It already has all the data we need; we just need it hooked up in a meaningful way.
  45.  
  46. :through is perfect for the job. By adding
  47.  
  48. > Doctor has_many :patients, :through => :appointments
  49.  
  50. > Patient has_many :doctors, :through => :appointments
  51.  
  52. we tell Rails about the existing associations, and how to find them.
  53.  
  54. Does that help answer your question? Let me know if you're still confused and I can point you to some external resources which might help!
  55.  
  56. Thanks,
  57. Anthony
  58.  
  59.  
  60. # SQL
  61.  
  62. Hi Student,
  63.  
  64. No problem! Glad to hear our talk helped.
  65.  
  66. Good for you being concerned about security! SQL injection is a pretty basic attack to defend, but understanding the technique can really give some insight into the mind of a hacker.
  67.  
  68. Let's say our site has a url
  69.  
  70. > book.php?id=6
  71.  
  72. which displays the book with id 6. In our code, we have some query to pull that book from the database:
  73. ```
  74. SELECT * FROM books WHERE id = 6
  75. ```
  76. The security issue arises when we are using public values (in this case, the book id in the url) to pull data from our database. Imagine instead of our friendly scenario above, a hacker visited the following url:
  77.  
  78. > books.php?id=6;DELETE * FROM books
  79.  
  80. If we aren't protecting from SQL injection, our query would then be:
  81. ```
  82. SELECT * FROM books WHERE id = 6;DELETE * FROM books
  83. ```
  84. As you can see, this query would do a lot more than just select a book. It would then delete all of the books.
  85.  
  86. There are several ways to combat this injection technique (proper database users, sql permissions, etc), but the main one we should be aware of as developers is ensuring the validity of our data. In the example above, we would check to make sure that the "id" is a number and nothing else before letting it anywhere close to a SQL statement.
  87.  
  88. Does that help?
  89.  
  90. Thanks,
  91. Anthony
  92.  
  93. # Angular/jQuery
  94.  
  95. Hi Student,
  96.  
  97. Great question!
  98.  
  99. Since you understand jQuery better, let's start there. Libraries like jQuery provide extra functionality to plain, boring (often called "vanilla") javascript. They are meant to fill perceived gaps in the base language, usually containing a specific, related set of methods. jQuery is pretty extensive, but generally provides a way to simplify and standardize event handling, animations, and moving around the document (finding different elements, groups of elements, all elements of a certain class, etc).
  100.  
  101. Generally, libraries are easily added to an existing site. Frameworks, on the other hand, are a little bit more complex.
  102.  
  103. When we talk about frameworks like Angular, we're talking about our html and javascript operating within a modified set of rules. Frameworks may appear similar to libraries on the surface (both are usually included via an external js file), but frameworks offer an even greater level of control over the underlying page.
  104.  
  105. It helps me to think of a library as something we add to our applications to gain additional functionality. A framework is something our applications are built in and on. To make things even more confusing, many frameworks will contain a number of libraries. As you can see, frameworks are a larger, more complex beast than libraries. Which is exactly why we teach libraries like jQuery before frameworks like Angular. :)
  106.  
  107. Hope that helps, let me know if you have any follow-up questions!
  108.  
  109. Cheers,
  110. Anthony
  111.  
  112. # Algorithms
  113.  
  114. Hi Student,
  115.  
  116. Well, to be honest you're a bit outside of my comfort zone!
  117.  
  118. I know the idea behind Big O is to help us understand the efficiency of various algorithms, and I have some experience in reading them, but I'll have to defer on the intricacies of calculating them.
  119.  
  120. Let me reach out to some of the other mentors here and find someone who can give you a better answer than I can. I'll let you know shortly, and sorry I couldn't be of more help myself.
  121.  
  122. Thanks,
  123. Anthony
  124.  
  125. # CSS
  126.  
  127. Hi Student!
  128.  
  129. No problem. It looks like you've run into a classic issue with the css float property. You're floating your .tier elements, presumably to get them to line up side by side. For many years, we had to use display hacks like these to get our elements to match increasingly complicated design specs. Unfortunately, that's not really float's purpose. Fortunately, we have much better options now.
  130.  
  131. Float was originally to get certain elements (back in the day it was almost always images) to act differently from paragraph text. You'd float the image left or right, and the text would magically wrap around. As layouts grew more complex and designing in tables grew out of fashion, float and clear became the main ways to control positioning of elements. There are still a number of dated results on search engines and sites like Stack Overflow which will contain some old positioning techniques.
  132.  
  133. The bright side, then, is that css contains MUCH better layout techniques now. For layouts like this one, we have a fairly new display property called "flex". When set on the parent element (.pricing-tiers in this case), display:flex treats the child elements as equally important. The browser does its best to fill the available space equally between the child elements, while still adhering to any individual rules they may have.
  134.  
  135. I may have gotten a bit off track with the history lesson there, but I'd recommend looking a bit more into Flexbox, the collection of css rules which include display:flex. It's very powerful technology and a huge help in creating cross-browser and cross-platform (phone, tablet, desktop) layouts.
  136.  
  137. **Try removing the float from your .tier elements and adding display:flex to your .pricing-tiers element.**
  138.  
  139. Good luck,
  140. Anthony
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement