diff --git a/app.js b/app.js index ab3ad10..2397746 100644 --- a/app.js +++ b/app.js @@ -1,39 +1,91 @@ // Important Note - No Built-in functions to be used -// Progression 1: Names and Input +// Progression 1: Names and Input // 1.1 Create a variable `ProGrad-1` with the driver's name. // 1.2 Print `"The driver's name is XXXX"`. // 1.3 Create a variable `ProGrad-2` with the navigator's name. // 1.4 Print `"The navigator's name is YYYY"`. +let ProGrad_1 = " Pavan Ganesh"; +console.log("The Driver's name is " + ProGrad_1); + +let ProGrad_2 = " Varsha Bisht"; +console.log("The navigator's name is " + ProGrad_2); // Progression 2: Control Statements - 1 // 2.1. Depending on which name is longer, print: // - The driver has the longest name, it has XX characters. or // - It seems that the navigator has the longest name, it has XX characters. or // - Wow, you both have equally long names, XX characters!. +let driver = ProGrad_1.length; +let navigator = ProGrad_2.length; +if (driver > navigator) { + console.log( + " The driver has the longest name, it has " + driver + " characters." + ); +} else if (driver < navigator) { + console.log( + "It seems that the navigator has the longest name, it has " + + navigator + + " characters" + ); +} else { + console.log( + "Wow, you both have equally long names, " + driver + " characters!." + ); +} // 2.2. Check if the string contains vowels or not. // - If it contains vowels, print the name, and also print the vowel letters along with the vowel index. or // - print no vowels -// - for example. In String ProGrad - o and a are vowels. Print ProGrad o a 2 5. +// - for example. In String ProGrad - o and a are vowels. Print ProGrad o a 2 5. + +let count = 0; +let vowel = "aeiou"; +for (let x = 0; x < ProGrad_2.length; x++) { + if (vowel.indexOf(ProGrad_2[x]) !== -1) { + count++; + } +} +console.log(ProGrad_2 + " no. of vowels " + count); // 2.3. Check if the string contains uppercase and lowercase characters Xx // - Print the number of upper case characters // - Print the number of lower case characters - +let ProGrad = "VasHa"; +var uppercase = 0; +var lowercase = 0; +for (var len = 0; len < ProGrad.length; len++) { + if (ProGrad[len] >= "a" && ProGrad[len] <= "z") lowercase++; + else uppercase++; +} +console.log("uppercase in " + ProGrad + " " + uppercase); +console.log("lowercase in " + ProGrad + " " + lowercase); // Progression 3: Control Statements - 2 // 3.1 Print all the characters of the driver's name, separated by a space and in capitals i.e. "ProGrad" // 3.2 Print all the characters of the navigator's name, in reverse order. i.e. "darGorP" - +var newString = ""; +for (var i = ProGrad_2.length - 1; i >= 0; i--) { + newString += ProGrad_2[i]; +} +console.log(newString); // 3.3 Merge both the characters such that driver is followed by Navigator like "ProGrad FACEPrep" // - Now bring the FACEPrep to the start and send ProGrad to the back like "FACEPrep ProGrad" - // 3.3 Depending on the lexicographic order of the strings, print: // - The driver's name goes first. // - Yo, the navigator goes first definitely. // - What?! You both have the same name? +driver = "ProGrad"; +navigator = "FACEPrep"; +console.log(driver + navigator); +console.log(navigator + " " + driver); + +if (ProGrad_1.localeCompare(ProGrad_2) == -1) + console.log("driver name goes first"); +else if (ProGrad_1.localeCompare(ProGrad_2) == 1) + console.log("navigator should come first"); +else console.log("both have same name"); // Bonus Time! // Bonus 1: @@ -53,4 +105,4 @@ // "put it up" // "Was it a car or a cat I saw?" and "No 'x' in Nixon". -// Hint: If you use Google to help you to find solution to this iteration, you might run into some solutions that use advanced string or array methods (such as join(), reverse(), etc.). However, try to apply the knowledge you currently have since you can build pretty nice solution with just using for loop, if-else statements with some break and continue... Just sayin' +// Hint: If you use Google to help you to find solution to this iteration, you might run into some solutions that use advanced string or array methods (such as join(), reverse(), etc.). However, try to apply the knowledge you currently have since you can build pretty nice solution with just using for loop, if-else statements with some break and continue... Just sayin' diff --git a/index.html b/index.html index e69de29..eb4204e 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,11 @@ + + +
+ + +