Skip to content

Instantly share code, notes, and snippets.

@wackywendell
Last active August 29, 2015 14:25
Show Gist options
  • Save wackywendell/ba66995a02434f909fd0 to your computer and use it in GitHub Desktop.
Save wackywendell/ba66995a02434f909fd0 to your computer and use it in GitHub Desktop.
random country
function country_update () {
var a = {}
a['China'] = 1371060000
a['India'] = 1274440000
a['United States'] = 321450000
a['Indonesia'] = 255461700
a['Brazil'] = 204633000
a['Pakistan'] = 190402000
a['Nigeria'] = 183523000
a['Bangladesh'] = 158712000
a['Russia'] = 146524812
a['Japan'] = 126890000
a['Mexico'] = 121005815
a['Philippines'] = 101776400
a['Vietnam'] = 91583000
a['Ethiopia'] = 90076012
a['Egypt'] = 89164100
a['Germany'] = 81083600
a['Iran'] = 78501300
a['Turkey'] = 77695904
a['Democratic Republic of the Congo'] = 71246000
a['France'] = 66162000
a['Thailand'] = 65104000
a['United Kingdom'] = 64800000
a['Italy'] = 60788845
a['South Africa'] = 54002000
a['South Korea'] = 51431100
a['Burma'] = 51419420
a['Colombia'] = 48224500
a['Tanzania'] = 47421786
a['Kenya'] = 46749000
a['Spain'] = 46439864
a['Argentina'] = 43131966
a['Ukraine'] = 42854106
a['Algeria'] = 40400000
a['Poland'] = 38484000
a['Sudan'] = 38435252
a['Iraq'] = 36004552
a['Canada'] = 35749600
a['Uganda'] = 34856813
a['Morocco'] = 33337529
a['Saudi Arabia'] = 31521418
a['Peru'] = 31151643
a['Uzbekistan'] = 31022500
a['Malaysia'] = 30649600
a['Venezuela'] = 30620404
a['Nepal'] = 28037904
a['Afghanistan'] = 27101365
a['Ghana'] = 27043093
a['Yemen'] = 25956000
a['Mozambique'] = 25727911
a['North Korea'] = 25155000
a['Angola'] = 24383301
a['Australia'] = 23838300
a['Taiwan'] = 23461562
a['Syria'] = 23295466
a['Ivory Coast'] = 22671331
a['Madagascar'] = 21842167
a['Cameroon'] = 21143237
a['Sri Lanka'] = 20675000
a['Romania'] = 19942642
a['Niger'] = 19268000
a['Burkina Faso'] = 18450494
a['Chile'] = 18006407
a['Kazakhstan'] = 17519000
a['Netherlands'] = 16911900
a['Malawi'] = 16310431
a['Mali'] = 16259000
a['Guatemala'] = 16176133
a['Ecuador'] = 15532000
a['Zambia'] = 15473905
a['Cambodia'] = 15405157
a['Chad'] = 13606000
a['Senegal'] = 13508715
a['Zimbabwe'] = 13061239
a['South Sudan'] = 11892934
a['Bolivia'] = 11410651
a['Belgium'] = 11245629
a['Cuba'] = 11238317
a['Somalia'] = 11123000
a['Rwanda'] = 10996891
a['Tunisia'] = 10982754
a['Haiti'] = 10911819
a['Greece'] = 10903704
a['Dominican Republic'] = 10652000
a['Guinea'] = 10628972
a['Czech Republic'] = 10538275
a['Portugal'] = 10477800
a['Benin'] = 10315244
a['Hungary'] = 9849000
a['Burundi'] = 9823827
a['Sweden'] = 9784445
a['Azerbaijan'] = 9636300
a['United Arab Emirates'] = 9577000
a['Belarus'] = 9481000
a['Honduras'] = 8725111
a['Austria'] = 8602112
a['Israel'] = 8358100
a['Tajikistan'] = 8354000
a['Switzerland'] = 8256000
a['Papua New Guinea'] = 7398500
a['Hong Kong (China)'] = 7264100
a['Bulgaria'] = 7202198
a['Togo'] = 7171000
a['Serbia'] = 7146759
a['Paraguay'] = 7003406
a['Laos'] = 6802000
a['Jordan'] = 6756140
a['Eritrea'] = 6738000
a['El Salvador'] = 6401240
a['Sierra Leone'] = 6319000
a['Libya'] = 6317000
a['Nicaragua'] = 6134270
a['Kyrgyzstan'] = 5935400
a['Denmark'] = 5668743
a['Finland'] = 5478002
a['Singapore'] = 5469700
a['Slovakia'] = 5421349
a['Norway'] = 5176998
a['Central African Republic'] = 4803000
a['Costa Rica'] = 4773130
a['Turkmenistan'] = 4751120
a['Palestine'] = 4682467
a['Republic of the Congo'] = 4671000
a['Ireland'] = 4609600
a['New Zealand'] = 4597210
a['Liberia'] = 4503000
a['Croatia'] = 4267558
a['Oman'] = 4159667
a['Lebanon'] = 4104000
a['Bosnia and Herzegovina'] = 3791622
a['Panama'] = 3764166
a['Georgia'] = 3729500
a['Mauritania'] = 3631775
a['Moldova'] = 3555200
a['Puerto Rico (U.S.)'] = 3548397
a['Somaliland (Somalia)'] = 3500000
a['Uruguay'] = 3415866
a['Kuwait'] = 3268431
a['Mongolia'] = 3027126
a['Armenia'] = 3006800
a['Lithuania'] = 2904391
a['Albania'] = 2893005
a['Jamaica'] = 2717991
a['Qatar'] = 2344557
a['Namibia'] = 2280700
a['Lesotho'] = 2120000
a['Slovenia'] = 2067364
a['Macedonia'] = 2065769
a['Botswana'] = 2056000
a['Latvia'] = 1980700
a['The Gambia'] = 1882450
a['Kosovo'] = 1827231
a['Guinea-Bissau'] = 1788000
a['Gabon'] = 1751000
a['Equatorial Guinea'] = 1430000
a['Trinidad and Tobago'] = 1328019
a['Bahrain'] = 1316500
a['Estonia'] = 1313271
a['Mauritius'] = 1261208
a['East Timor'] = 1212107
a['Swaziland'] = 1119375
a['Djibouti'] = 900000
a['Fiji'] = 859178
a['Cyprus'] = 858000
a['Réunion (France)'] = 844994
a['Comoros'] = 784745
a['Bhutan'] = 762880
a['Guyana'] = 746900
a['Macau (China)'] = 640700
a['Montenegro'] = 620029
a['Solomon Islands'] = 581344
a['Luxembourg'] = 562958
a['Suriname'] = 534189
a['Cape Verde'] = 518467
a['Western Sahara'] = 510713
a['Transnistria'] = 505153
a['Malta'] = 445426
a['Guadeloupe (France)'] = 405739
a['Brunei'] = 393372
a['Martinique (France)'] = 381326
a['The Bahamas'] = 368390
a['Belize'] = 358899
a['Maldives'] = 341256
a['Iceland'] = 329740
a['Northern Cyprus'] = 294396
a['Barbados'] = 285000
a['New Caledonia (France)'] = 268767
a['French Polynesia (France)'] = 268270
a['Vanuatu'] = 264652
a['Abkhazia'] = 240705
a['French Guiana (France)'] = 239648
a['Mayotte (France)'] = 212645
a['Samoa'] = 187820
a['São Tomé and Príncipe'] = 187356
a['Saint Lucia'] = 185000
a['Guam (U.S.)'] = 159358
a['Curaçao (Netherlands)'] = 154843
a['Nagorno-Karabakh Republic'] = 146573
a['Saint Vincent and the Grenadines'] = 109000
a['Aruba (Netherlands)'] = 107394
a['Kiribati'] = 106461
a['United States Virgin Islands (U.S.)'] = 106405
a['Grenada'] = 103328
a['Tonga'] = 103252
a['Federated States of Micronesia'] = 101351
a['Jersey (UK)'] = 99000
a['Seychelles'] = 89949
a['Antigua and Barbuda'] = 86295
a['Isle of Man (UK)'] = 84497
a['Ceuta (Spain)'] = 82376
a['Melilla (Spain)'] = 78476
a['Andorra'] = 76949
a['Dominica'] = 71293
a['Guernsey (UK)'] = 65150
a['Bermuda (UK)'] = 64237
a['Marshall Islands'] = 56086
a['Greenland'] = 55984
a['Cayman Islands (UK)'] = 55691
a['American Samoa (U.S.)'] = 55519
a['Saint Kitts and Nevis'] = 55000
a['Northern Mariana Islands (U.S.)'] = 53883
a['South Ossetia'] = 51547
a['Faroe Islands (Denmark)'] = 48724
a['Sint Maarten (Netherlands)'] = 37429
a['Liechtenstein'] = 37370
a['Monaco'] = 37800
a['Saint-Martin (France)'] = 36522
a['San Marino'] = 32789
a['Turks and Caicos Islands (UK)'] = 31458
a['Gibraltar (UK)'] = 30001
a['Åland Islands (Finland)'] = 28875
a['British Virgin Islands (UK)'] = 28054
a['Palau'] = 20901
a['Bonaire (Netherlands)'] = 17408
a['Cook Islands (New Zealand)'] = 14974
a['Anguilla (UK)'] = 13452
a['Wallis and Futuna (France)'] = 13135
a['Tuvalu'] = 11323
a['Nauru'] = 10084
a['Saint Barthélemy (France)'] = 9269
a['Saint Pierre and Miquelon (France)'] = 6069
a['Montserrat (UK)'] = 4922
a['Sint Eustatius (Netherlands)'] = 4020
a['Saint Helena, Ascension and Tristan da Cunha (UK)'] = 4000
a['Falkland Islands (UK)'] = 3000
a['Svalbard and Jan Mayen (Norway)'] = 2562
a['Norfolk Island (Australia)'] = 2302
a['Christmas Island (Australia)'] = 2072
a['Saba (Netherlands)'] = 1991
a['Niue (New Zealand)'] = 1613
a['Tokelau (NZ)'] = 1411
a['Vatican City'] = 839
a['Cocos (Keeling) Islands (Australia)'] = 550
a['Wake Island (U.S.)'] = 188
a['French Southern and Antarctic Lands (France)'] = 140
a['Pitcairn Islands (UK)'] = 56
a['Midway Atoll (U.S.)'] = 40
var country_header = document.getElementById('countryheader')
country_header.style.opacity = 0
setTimeout(function () {
var opacity = 0
var animate = setInterval(function () {
opacity += 0.05
if (opacity >= 1) {
clearInterval(animate)
}
country_header.style.opacity = opacity
}, 100)
}, 2000)
var sorted_keys = Object.keys(a)
var sum = 0
sorted_keys.map(function (key) {
sum += a[key]
})
var person_number = Math.floor(Math.random() * sum)
var running_sum = 0
for (var i = 0; i < sorted_keys.length; i++) {
var key = sorted_keys[i]
running_sum += a[key]
if (running_sum > person_number) {
document.getElementById('country').innerHTML = key
break
}
};
};
window.onload = country_update
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Country</title>
<meta name="description" content="">
<!-- Mobile-friendly viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Style sheet link -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="all">
<link href="one-page-wonder.css" rel="stylesheet">
<script type="text/javascript" src="countries.js"></script>
</head>
<body>
<header class="header-image">
<div class="headline">
<div class="container">
<h2>Welcome to the Earth.</h2>
<h3>You are now a citizen of</h3>
<h1 id="countryheader"><span id="country" class="country">A COUNTRY</span>!</h1>
</div>
</div>
</header>
</body>
</html>
/*!
* Taken from: Start Bootstrap - One Page Wonder HTML Template
* (http://startbootstrap.com)
* Code licensed under the Apache License v2.0.
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
*/
.header-image {
display: block;
width: 100%;
text-align: center;
background: url('blue-marble-earth-wallpaper-1920.jpg') no-repeat center center scroll;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
.headline {
padding: 200px 0;
}
.headline h1 {
font-size: 110px;
background: #fff;
background: rgba(255,255,255,0.9);
}
.headline h2 {
font-size: 63px;
background: #fff;
background: rgba(255,255,255,0.9);
}
.headline h3 {
font-size: 48px;
background: #fff;
background: rgba(255,255,255,0.9);
}
.country {
-webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s; /* Firefox < 16 */
-ms-animation: fadein 2s; /* Internet Explorer */
-o-animation: fadein 2s; /* Opera < 12.1 */
animation: fadein 2s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment