Skip to content

Instantly share code, notes, and snippets.

@chien
chien / cm answer.md
Last active November 13, 2016 08:17
CM Answers

###JavaScript### Hi,

The main problem of this code is the variable scope of btnNum. When you define onclick callback function, it will not be called immediately, but will be triggered when users click one of the buttons. And by the time when users click a button, the btnNum is already set to 3. (It increments three times from zero to three.) And the onclick callback function will use the last btnNum value - 3 to run the callback function and since prizes array don't have corresponding element with the index of 3. ** prizes[btnNum] ** return undefined.

The following is the working version of code for your reference. Please let me know if you have further question. Happy to walk through this code with you in the call.

var prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!'];
# -*- coding: utf-8 -*-
"""
LICENSE: BSD (same as pandas)
example use of pandas with oracle mysql postgresql sqlite
- updated 9/18/2012 with better column name handling; couple of bug fixes.
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle.
to do:
save/restore index (how to check table existence? just do select count(*)?),
finish odbc,
class MembershipTransitionController < ApplicationController
def update
if @membership.fire_events(params[:event_name])
# handle success transition case
else
# handle failed transition
end
end
end