Skip to content

Instantly share code, notes, and snippets.

@fitradev
Created May 29, 2018 10:43
Show Gist options
  • Save fitradev/65d14ef56a4a082caa10cc55de00f3fe to your computer and use it in GitHub Desktop.
Save fitradev/65d14ef56a4a082caa10cc55de00f3fe to your computer and use it in GitHub Desktop.
String Challenges created by fitradev - https://repl.it/@fitradev/String-Challenges
console.log("----1. Let's Form A Setence----\n");
var word = 'JavaScript';
var second = 'is';
var third = 'awesome';
var fourth = 'and';
var fifth = 'I';
var sixth = 'love';
var seventh = 'it!';
console.log(word + ' ' + second + ' ' + third + ' ' +fourth + ' ' +fifth+ ' ' +sixth+ ' ' +seventh);
console.log("\n\n---2. Index Accessing - 1 by 1----\n");
var word = 'wow JavaScript is so cool';
var exampleFirstWord = word[0] + word[1] + word[2];
var secondWord = word[4] + word[5] + word[6]+word[7] + word[8] + word[9]+word[10] + word[11] + word[12]+ word[13]; // do your own!
var thirdWord = word[15]+ word[16]; // do your own!
var fourthWord = word[18]+ word[19]; // do your own!
var fifthWord = word[20]+ word[21]+ word[22]+ word[23]+ word[24]; // do your own!
console.log('First Word: ' + exampleFirstWord);
console.log('Second Word: ' + secondWord);
console.log('Third Word: ' + thirdWord);
console.log('Fourth Word: ' + fourthWord);
console.log('Fifth Word: ' + fifthWord);
console.log("\n\n----3. Breaking Sentence (Again) using Substring----\n");
var word3 = 'wow JavaScript is so cool';
var exampleFirstWord3 = word3.substring(0, 3);
var secondWord3 = word3.substring(4, 14); // do your own!
var thirdWord3 = word3.substring(15, 17); // do your own!
var fourthWord3 = word3.substring(18, 20); // do your own!
var fifthWord3 = word3.substring(21, 25); // do your own!
console.log('First Word: ' + exampleFirstWord3);
console.log('Second Word: ' + secondWord3);
console.log('Third Word: ' + thirdWord3);
console.log('Fourth Word: ' + fourthWord3);
console.log('Fifth Word: ' + fifthWord3);
console.log("\n\n----4. Breaking Sentence (yet Again) and Count Each Length----\n");
var word4 = 'wow JavaScript is so cool';
var exampleFirstWord4 = word4.substring(0, 3);
var secondWord4 = word4.substring(4, 14); // do your own!
var thirdWord4 = word4.substring(15, 17); // do your own!
var fourthWord4 = word4.substring(18, 20); // do your own!
var fifthWord4 = word4.substring(21, 25); // do your own!
var firstWordLength = exampleFirstWord4.length;
var secondWord4length = secondWord4.length;
var thirdWord4length = thirdWord4.length;
var fourthWord4length = fourthWord4.length;
var fifthWord4length = fifthWord4.length;
// create new variables around here
console.log('First Word: ' + exampleFirstWord4 + ', with length: ' + firstWordLength);
console.log('Second Word: ' + secondWord4 + ', with length: ' + secondWord4length);
console.log('Third Word: ' + thirdWord4 + ', with length: ' + thirdWord4length);
console.log('Fourth Word: ' + fourthWord4 + ', with length: ' + fourthWord4length);
console.log('Fifth Word: ' + fifthWord4 + ', with length: ' + fifthWord4length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment