Interview Question Practice Series: Pt. 2

Continuing right where we left off:

Question 6

(FB front-end engineering question) Using HTML & CSS, create an image that displays another image when the user hovers over the image. Align the image to the bottom right of the screen. 
You can see the code by clicking here.
  1. This one is very straightforward if you've used a bit of CSS here and there. You need two HTML img elements and need to assign classes to them.
  2. The rest of this just tests your CSS knowledge, mainly the "display" property. You can just set up the display of your first image to be "block" - you can opt to set up other properties to make it look nice, setting a relative position, etc.
  3. After that, you set the bottom and right properties of your second image to be "0" so that it aligns to the bottom right of the screen. Display should be set to "none" so that it's hidden until a user interaction forces the view.
  4. Lastly, we look at the "hover" pseudoclass (simply defines a special state of an element). We specify that we are targeting the hover for the first image and use teh "+" operator to say that we want to overlay the second image.

Question 7

(FB iOS engineering question)This one is the most challenging out of what we've covered so far, in my opinion (mainly because it involves domain framework knowledge and not general programming knowledge). iOS developers have the option to create a dispatch queue that executes an action after a delay (dispatch_after(when, queue, block).It isn't easy to cancel this dispatch queue once it's set up - implement a cancellable_dispatch_after method to allow for easy cancellation of the block.
  1. The first thing to note is what parameters there are in a dispatch_after method. The "when" is a dispatch_time object, the queue is just the queue on which to submit the block, and the block is just that!
  2. If we're delaying a UI action based on a user interaction (pressing a button, perhaps), the queue we're executing on is obviously the main queue. Make sure you're aware of that in case you're ever asked in an interview.
  3. Let's think of a use case for cancelling a block that is being executed after a delay. Say you have an animation that needs to be cancelled if the user touches the screen in the middle of the animation. We could have a boolean value that determines whether or not the screen has been tapped (we can set it to false as a class variable and then in a gesture delegate method we could set it to true). In our cancellable block, if the boolean is true, it means the user has tapped the screen and we can cancel the animation block.