Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- // returns the longest country name
- function longestCountryName(country_name) {
- return country_name.reduce(function(lname,country) {
- return lname.length > country.length ? lname : country;
- },
- "");
- }
- console.log(longestCountryName(["Australia", "Germany", "United States of America"]));
- // checks to see if a number is prime or not
- function testPrime(n) {
- if (n === 1) {
- return false;
- } else if (n === 2) {
- return true;
- }else {
- for (var x = 2; x < n; x++) {
- if (n % x === 0) {
- return false;
- }
- }
- return true;
- }
- }
- console.log(testPrime(31));
- // returns the sentence with the first letters uppercased
- function uppercase(str) {
- var array1 = str.split(' ');
- var newArray = [];
- for (var x = 0; x < array1.length; x++) {
- newArray.push(array1[x].charAt(0).toUpperCase() + array1[x].slice(1));
- }
- return newArray.join(' ');
- }
- console.log(uppercase("the quick brown fox"));
- // Accepts a string as a parameter and counts the number of vowels in the string
- function vowel_count(str) {
- var vowel_list = "aeiouAEIOU";
- var vcount = 0;
- for (var x = 0; x < str.length; x++) {
- if (vowel_list.indexOf(str[x]) !== -1) {
- vcount += 1;
- }
- }
- return vcount;
- }
- console.log(vowel_count("The quick brown fox"));
- // finds the longest word within a string
- function findLongestWord(str) {
- var arr = str.match(/\w[a-z]{0,}/gi);
- var result = arr[0];
- for (var x = 1; x < arr.length; x++) {
- if(result.length < arr[x].length) {
- result = arr[x];
- }
- }
- return result;
- }
- console.log(findLongestWord('Web Development Tutorial'));
- // counts the number of occurences of the specified letter within the string
- function charCount(str,letter) {
- var letter_count = 0;
- for (var position = 0; position < str.length; position++) {
- if (str.charAt(position) === letter) {
- letter_count++;
- }
- }
- return letter_count;
- }
- console.log(charCount('doodle mcnoodle', 'o'));
- // generates a string ID (specified length) of random characters
- function makeId(l) {
- var text = "";
- var char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- for (var i = 0;i < l; i++) {
- text += char_list.charAt(Math.floor(Math.random() * char_list.length));
- }
- return text;
- }
- console.log(makeId(8));
- // returns a passed strings with letters in alphabetical order
- function alphabet_order(str) {
- return str.split('').sort().join('');
- }
- console.log(alphabet_order("webmaster"));
- //returns only the numbers in the array bigger than the val
- function BiggerEl(val) {
- return function(evalue, index, array) {
- return (evalue >= val);
- };
- }
- var result = [11,45,4,31,64,10,5,6].filter(BiggerEl(10));
- console.log(result);
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">// returns the longest country name
- function longestCountryName(country_name) {
- return country_name.reduce(function(lname,country) {
- return lname.length > country.length ? lname : country;
- },
- "");
- }
- console.log(longestCountryName(["Australia", "Germany", "United States of America"]));
- // checks to see if a number is prime or not
- function testPrime(n) {
- if (n === 1) {
- return false;
- } else if (n === 2) {
- return true;
- }else {
- for (var x = 2; x < n; x++) {
- if (n % x === 0) {
- return false;
- }
- }
- return true;
- }
- }
- console.log(testPrime(31));
- // returns the sentence with the first letters uppercased
- function uppercase(str) {
- var array1 = str.split(' ');
- var newArray = [];
- for (var x = 0; x < array1.length; x++) {
- newArray.push(array1[x].charAt(0).toUpperCase() + array1[x].slice(1));
- }
- return newArray.join(' ');
- }
- console.log(uppercase("the quick brown fox"));
- // Accepts a string as a parameter and counts the number of vowels in the string
- function vowel_count(str) {
- var vowel_list = "aeiouAEIOU";
- var vcount = 0;
- for (var x = 0; x < str.length; x++) {
- if (vowel_list.indexOf(str[x]) !== -1) {
- vcount += 1;
- }
- }
- return vcount;
- }
- console.log(vowel_count("The quick brown fox"));
- // finds the longest word within a string
- function findLongestWord(str) {
- var arr = str.match(/\w[a-z]{0,}/gi);
- var result = arr[0];
- for (var x = 1; x < arr.length; x++) {
- if(result.length < arr[x].length) {
- result = arr[x];
- }
- }
- return result;
- }
- console.log(findLongestWord('Web Development Tutorial'));
- // counts the number of occurences of the specified letter within the string
- function charCount(str,letter) {
- var letter_count = 0;
- for (var position = 0; position < str.length; position++) {
- if (str.charAt(position) === letter) {
- letter_count++;
- }
- }
- return letter_count;
- }
- console.log(charCount('doodle mcnoodle', 'o'));
- // generates a string ID (specified length) of random characters
- function makeId(l) {
- var text = "";
- var char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- for (var i = 0;i < l; i++) {
- text += char_list.charAt(Math.floor(Math.random() * char_list.length));
- }
- return text;
- }
- console.log(makeId(8));
- // returns a passed strings with letters in alphabetical order
- function alphabet_order(str) {
- return str.split('').sort().join('');
- }
- console.log(alphabet_order("webmaster"));
- //returns only the numbers in the array bigger than the val
- function BiggerEl(val) {
- return function(evalue, index, array) {
- return (evalue >= val);
- };
- }
- var result = [11,45,4,31,64,10,5,6].filter(BiggerEl(10));
- console.log(result);</script></body>
- </html>
Add Comment
Please, Sign In to add comment