   ###
   # Use the current challenge metadata to fill in the web page
   ###
+  console.log('updating challenge')
   request = $.ajax {url: "/api/c/challenges/#{challenge}"}
   request.done (data) ->
     currentChallenge = data.challenge

  #
  #
  if challenge?
    updateChallenge(challenge)
    updateStats(challenge)
    getTask(near)
  else
    if not difficulty
      difficulty = 1
    if not near
      near = "#{map.getCenter().lng}|#{map.getCenter().lat}"
    getNewChallenge(difficulty, near)


  ###
  # Gets a challenge based on difficulty and location
  ###
  console.log('getting new challenge')
  # near default was already set in the init function, no need to do it again here?
  near = "#{map.getCenter().lng}|#{map.getCenter().lat}" if not near
  url = "/api/c/challenges?difficulty=#{difficulty}&contains=#{near}"
  request = $.ajax {url: "/api/c/challenges?difficulty=#{difficulty}&contains=#{near}"}
  request.done (data) ->
    # for some reason we don't get challenge.slug but we do get challenge.id which is the slug?
    challenge = data.challenges[0].id
    console.log(JSON.stringify(challenge, null, 4))
    console.log('we got a challenge: ' + challenge)
    updateChallenge(challenge)
    updateStats(challenge)
    getTask(near)
