From 0c0c42880d085839190195f416235c61cc2c5650 Mon Sep 17 00:00:00 2001 From: Hasan Zengin Date: Tue, 27 Jan 2026 10:30:11 -0500 Subject: [PATCH] Finish programming challenge --- server.py | 58 +++++++++++++------------------------------- static/scoreboard.js | 2 +- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/server.py b/server.py index 372a266c..a6b80d3f 100644 --- a/server.py +++ b/server.py @@ -1,62 +1,38 @@ from flask import Flask from flask import render_template from flask import Response, request, jsonify + app = Flask(__name__) scoreboard = [ - { - "id": 1, - "name": "Boston Bruins", - "score": 7 - }, - - { - "id": 2, - "name": "Tampa Bay Lightning", - "score": 5 - }, - - { - "id": 3, - "name": "Toronto Maple Leafs", - "score": 2 - }, - - { - "id": 4, - "name": "Florida Panthers", - "score": 1 - }, - - { - "id": 5, - "name": "Buffalo Sabres", - "score": 1 - }, + {"id": 1, "name": "Boston Bruins", "score": 7}, + {"id": 2, "name": "Tampa Bay Lightning", "score": 5}, + {"id": 3, "name": "Toronto Maple Leafs", "score": 2}, + {"id": 4, "name": "Florida Panthers", "score": 1}, + {"id": 5, "name": "Buffalo Sabres", "score": 1}, ] -@app.route('/') +@app.route("/") def show_scoreboard(): - return render_template('scoreboard.html', scoreboard = scoreboard) + return render_template("scoreboard.html", scoreboard=scoreboard) + -@app.route('/increase_score', methods=['GET', 'POST']) +@app.route("/increase_score", methods=["GET", "POST"]) def increase_score(): global scoreboard - json_data = request.get_json() - team_id = json_data["id"] - + json_data = request.get_json() + team_id = json_data["id"] + for team in scoreboard: if team["id"] == team_id: team["score"] += 1 - return jsonify(scoreboard=scoreboard) - - -if __name__ == '__main__': - app.run(debug = True) - + scoreboard.sort(key=lambda x: x["score"], reverse=True) + return jsonify(scoreboard=scoreboard) +if __name__ == "__main__": + app.run(debug=True) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..f48d7c1c 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -32,7 +32,7 @@ function increase_score(id){ contentType: "application/json; charset=utf-8", data : JSON.stringify(team_id), success: function(result){ - + display_scoreboard(result.scoreboard); }, error: function(request, status, error){ console.log("Error");