Skip to content

Instantly share code, notes, and snippets.

View kuznetsovandrey76's full-sized avatar

Andrey Kuznetsov kuznetsovandrey76

View GitHub Profile
@kuznetsovandrey76
kuznetsovandrey76 / JavaScript
Last active November 17, 2016 19:30
my JavaScript link
We couldn’t find that file to show.
@kuznetsovandrey76
kuznetsovandrey76 / Max in Array
Last active December 18, 2016 12:35
Find max value in Array
var arr = [1, -2, 3, 0];
var max = Math.max.apply(Math, arr);
console.log(max) // 3
@kuznetsovandrey76
kuznetsovandrey76 / Random
Created December 18, 2016 12:34
without repeats
var text = document.getElementById('text'); // <div id="text"></div>
var quotes = '["1", "2", "3"]'; // any array (JSON or not JSON)
quotes = JSON.parse(quotes);
text.onclick = function foo() {
var random = parseInt(Math.random()*quotes.length);
var quote = quotes[random];
if(text.innerHTML == quote) {
return foo(); // start the function again
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://kuznetsovandrey76.github.io/chingu-map/data.json');
xhr.send();
xhr.onload = function() {
console.log('answer:' + xhr.response);
};
January 2017
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Antic|Dosis|Exo|Josefin+Sans|Maven+Pro|Muli:300|Nobile|Oxygen:300|Poppins:300|Raleway|Ruluko" rel="stylesheet">
<title>Fonts</title>
<style>
* {
margin: 0;
var div = document.querySelectorAll('div'),
result;
for (var i = 0; i < div.length; i++) {
result = div[i];
result.addEventListener('click', function() {
alert(this.innerHTML);
});
}
var arr = [
[1,2],
[3,4],
[5,6]
];
var temp = [];
for (var i = 0; i < arr.length; i++) {
temp.push(arr[i][0], arr[i][1]);
}
// HTML
<div id="first" class="content"></div>
<div id="second" class="content"></div>
//JS
var first = document.querySelector("#first");
var second = document.querySelector("#second");
var clickedLink = {
first: 0,