This file contains 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
$(document).ready(function(){ | |
//get the quote api information with Ajax | |
getQuote(); | |
function getQuote(){ | |
$.ajax({ | |
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=1", | |
type: "GET", | |
data: {}, | |
dataType: "json", | |
beforeSend: function(xhr) { |
This file contains 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
$(document).ready(function(){ | |
//get the quote api information with Ajax | |
getQuote(); | |
var bgCols = ['#2e67f7','#ea5c30','#38b582','#683a20','#59357d', '#555']; | |
function getQuote(){ | |
var num = Math.floor(Math.random()*6+1); | |
$.ajax({ | |
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=1", | |
type: "GET", |
This file contains 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
$(document).ready(function(){ | |
var latitude = ''; | |
var longitude = ''; | |
navigator.geolocation.getCurrentPosition(function(position) { | |
latitude = position.coords.latitude; | |
longitude = position.coords.longitude; | |
console.log('lat=' + latitude + ' long=' + longitude); | |
}); | |
}); |
This file contains 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
function convertToRoman(num) { | |
var singles = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"]; | |
var tens = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"]; | |
var hundreds = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"]; | |
var thousands = ["", "M", "MM", "MMM", "MMMM"]; | |
//turn the number to a string, split individual characters and then turn each one to a number. | |
var length = num.toString().length; | |
var numbers = num.toString().split("").map(Number); | |
var roman = ''; |
This file contains 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
function whatIsInAName(collection, source) { | |
// What's in a name? | |
var arr = []; | |
// Only change code below this line | |
var sKeyVal = []; | |
sKeyVal.push( Object.keys(source) ); //find the keys in the source | |
sKeyVal.push( Object.values(source) ); //find the values in source | |
var match = 0; | |
This file contains 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
function myReplace(str, before, after) { | |
//search for the before string and then use a function to check for capitalisation before replacing. | |
str = str.replace(before, function(x){ | |
//check whether the first letter of before is a capital | |
//replace after with a capitalised first letter and then | |
//the rest of the string, cannot just replace first letter as its read only. | |
if(before[0] == before[0].toUpperCase()){ | |
after = after[0].toUpperCase() + after.slice(1); | |
return after; | |
} |
This file contains 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
function translatePigLatin(str) { | |
var vowels = ['a','e','i','o','u']; | |
var strArr = str.split(''); //split the string into an array | |
//walk through the string array and test for vowels. | |
for(var i = 0; i<strArr.length; i++){ | |
//if the letter is a vowel create the new string | |
if(vowels.includes(strArr[i])){ | |
//if the first letter is a vowel just add 'way' to the end. | |
if(i == 0){ |
This file contains 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
function pairElement(str) { | |
str = str.split(""); | |
var pairs = []; | |
for(var i = 0; i < str.length; i++){ | |
switch (str[i]) { | |
case "C": | |
pairs.push(["C", "G"]); | |
break; | |
case "G": |
This file contains 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
function fearNotLetter(str) { | |
//in unicode A=65 and Z=90, a=97 and z=122 | |
//get the starting letter's unicode, and then add one to check the next letter | |
var start = str.charCodeAt(0) + 1; | |
var missing = ''; //store missing letters | |
//loop over the string, get the letters unicode value and compare it to what the next letter's code should be: | |
for(var i = 1; i < str.length; i++){ | |
//if the codes don't match append the letter to the variable | |
if(str.charCodeAt(i) !== start){ |
This file contains 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
function booWho(bool) { | |
// What is the new fad diet for ghost developers? The Boolean. | |
//check if the value 'bool' is strictly true or false, this means the value is a Boolean Primitive and should return true. | |
//Everything else should return false. | |
if(bool === true || bool === false){ | |
return true; | |
} | |
else { | |
return false; | |
} |
OlderNewer