Created
August 10, 2016 01:13
-
-
Save inlightmedia/befe866da3f3befbd34246370d6e0b34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="http://www.parsecdn.com/js/parse-latest.js"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/********************************************** | |
# Basic Queries # | |
Using the classes Player and Team which should have been | |
populated in your parse database in the Getting Started section, | |
create queries which answer the following questions. | |
1 - Who is the youngest player? | |
2 - What has the largest jerseyNumber? | |
3 - How many players who play in position "Keeper" also have a nationality of "Wales"? | |
4 - What are the names of the 11th, 12th and 13th most expensive players? | |
***********************************************/ | |
Parse.initialize("<APP_ID GOES HERE>"); | |
Parse.serverURL = '<SERVER_URL GOES HERE>'; | |
var Player = Parse.Object.extend("Player"); | |
// 1 | |
var q = new Parse.Query("Player"); | |
q.descending("dateOfBirth"); | |
q.first("dateOfBirth") | |
.then(function (result) { | |
// console.log(result); | |
console.log(result.get("name") + " is the youngest."); | |
});; | |
// 2 | |
var q2 = new Parse.Query("Player"); | |
q2.descending("jerseyNumber"); | |
q2.first().then(function (num) { | |
console.log(num.get("name") + " has the largest jersey number."); | |
}, function (e) {}); | |
// 3 | |
var q3 = new Parse.Query("Player"); | |
q3.equalTo("position", "Keeper"); | |
q3.equalTo("nationality", "Wales"); | |
q3.find().then(function (players) { | |
console.log(players.length + " have the nationality of Wales and position of Keeper"); | |
return players; | |
}, function error(e) {}); | |
// 4 | |
var q4 = new Parse.Query("Player"); | |
q4.descending("marketValue"); | |
q4.find().then(function success(players) { | |
console.log(players[10].get("name") , players[11].get("name") , players[12].get("name")); | |
}, function error(e) {}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment