var randomColor = {
list: [
'rgb(255,255,0)',
'rgb(255,0,0)',
'rgb(0,255,0)',
'rgb(0,51,0)'
],
already: [],
random: function () {
return this.list[Math.floor(Math.random() * this.list.length)];
},
get: function () {
var color = this.random();
if (this.already.length >= this.list.length) {
this.already = [];
return color;
}
if (this.already.indexOf(color) !== -1) {
return this.get();
} else {
this.already.push(color);
return color;
}
}
};
var total = 0, count = 1;
while ( count <= 10) {
total = total + count;
count = count + 1;
}
# 1
while ( count <= 10) {
total = 0 + 1;
count = 1 + 1;
}
// total = 1
// count = 2
# 2
while ( count <= 10) {
total = 1 + 2;
count = 2 + 1;
}
// total = 3
// count = 3
# 3
while ( count <= 10) {
total = 3 + 3;
count = 3 + 1;
}
// total = 6
// count = 4
# 4
while ( count <= 10) {
total = 6 + 4;
count = 4 + 1;
}
// total = 10
// count = 5
# 5
while ( count <= 10) {
total = 10 + 5;
count = 5 + 1;
}
// total = 15
// count = 6
# 6
while ( count <= 10) {
total = 15 + 6;
count = 6 + 1;
}
// total = 21
// count = 7
# 7
while ( count <= 10) {
total = 21 + 7;
count = 7 + 1;
}
// total = 28
// count = 8
# 8
while ( count <= 10) {
total = 28 + 8;
count = 8 + 1;
}
// total = 36
// count = 9
# 9
while ( count <= 10) {
total = 36 + 9;
count = 9 + 1;
}
// total = 45
// count = 10
# 10
while ( count <= 10) {
total = 45 + 10;
count = 10 + 1;
}
// total = 55
// count = 11
function getTrack(id,cb) {
var getParams = {
audios: id,
access_token: '***'
};
$.getJSON('https://api.vk.com/method/audio.getById', getParams, function (json) {
if (json.error !== undefined) {
var errorCode = json.error.error_code;
if (errorCode == 14) {
console.log('Captcha!');
} else if (errorCode == 6) {
console.log('Too many requests! Try again.');
return getTrack(id);
}
} else {
cb(json.response['0']);
}
});
}
$('.play , .download').click(function () {
var trackItem = $(this).parent('.track'),
trackId = trackItem.attr('data-id');
if (trackItem.attr('data-url') !== undefined) {
} else {
getTrack( trackId, function (id) {
console.log(id);
});
}
});
<div class="row same-cols">
<div class="col-md-6 same-height">1</div>
<div class="col-md-6 same-height">1</div>
</div>
$('.same-cols').each(function(){
var height = 0,
cols = $(this).find('.same-height');
cols.each(function(){
if( $(this).innerHeight() > height ) height = $(this).innerHeight();
});
cols.css( 'height', height + 'px');
});
var fs = require('fs'),
path = __dirname + '/images/';
fs.readdir(path, function(err, items) {
for (var i=0; i<items.length; i++) {
console.log(items[i]);
}
});