From 52f8d7d67a3a34b4f41467c8973fdbe9b8c7317d Mon Sep 17 00:00:00 2001 From: Electra Heart Date: Tue, 19 May 2020 02:49:55 +0530 Subject: [PATCH] FSJ0520A101 --- app.js | 135 ++++++++++++++++++++++++++++++++++++++++++++++++----- index.html | 15 ++++++ 2 files changed, 138 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index ab3ad10..b8b609c 100644 --- a/app.js +++ b/app.js @@ -1,39 +1,133 @@ // Important Note - No Built-in functions to be used // 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"`. +var ProGrad_1='Elizabeth'; +console.log("The driver's name is "+ProGrad_1); +var ProGrad_2='Stefani'; +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!. +len1=ProGrad_1.length; +len2=ProGrad_2.length; +if(len1 > len2) +{ + console.log('Looks like the driver has the longer name. Their name has '+len1+' characters.'); +} +else if(len1 < len2) +{ + console.log('Looks like the driver has the longer name. Their name has '+len2+' characters.'); +} +else{ + console.log('Looks like they both have equally long names'); +} -// 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. +// 2.2. Check if the string contains vowels or not. var vowel_list = 'aeiouAEIOU'; + for(var x = 0; x < len1 ; x++) { + if (vowel_list.indexOf(ProGrad_1[x]) !== -1) + { + console.log(ProGrad_1[x]+' Vowel At '+x); + } + else{ + console.log('No vowels'); + } + + } + + for(var x = 0; x < len2 ; x++) { + if (vowel_list.indexOf(ProGrad_2[x]) !== -1) + { + console.log(ProGrad_2[x]+' Vowel At '+x); + } + else{ + console.log('No vowels'); + } + + } // 2.3. Check if the string contains uppercase and lowercase characters Xx +//for driver's name +// - Print the number of upper case characters +var upper=0; +var lower=0; +for(var x=0;x=0; x--){ + newpro2+=ProGrad_2[x]; + } + return newpro2; + } + revstring(ProGrad_2); // 3.3 Merge both the characters such that driver is followed by Navigator like "ProGrad FACEPrep" + +console.log(ProGrad_1+" "+ProGrad_2); // - Now bring the FACEPrep to the start and send ProGrad to the back like "FACEPrep ProGrad" +console.log(ProGrad_2+" "+ProGrad_1); // 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? +if(ProGrad_1.localeCompare(ProGrad_2)<0){ + console.log("The driver's name goes first."); + } + else if(ProGrad_1.localeCompare(ProGrad_2)>0){ + console.log("Yo, the navigator goes first definitely."); + } + else{ + console.log("What?! You both have the same name?"); + } // Bonus Time! // Bonus 1: @@ -41,6 +135,10 @@ // Generate 3 paragraphs. Store the text in a variable type of string. // Make your program count the number of words in the string. // Make your program count the number of times the Latin word et appears. +function WordCount(str) { + return str.split(" ").length; + } + // Bonus 2: // Create a new variable phraseToCheck and have it contain some string value. Write a code that will check if the value we assigned to this variable is a Palindrome. Here are some examples of palindromes: @@ -52,5 +150,18 @@ // "taco cat" // "put it up" // "Was it a car or a cat I saw?" and "No 'x' in Nixon". +function checkpal(str){ + for(i=str.length-1;i>=0;i++){ + rev.push(str[i]); + } + rev.toString(); + if(rev==str){ + console.log("It's a palindrome."); + } + else{ + console.log("It's not a palindrome."); + } + } + checkpal('Was it a car or a cat I saw?'); // 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..30d67df 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + Lab + + +
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

+

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

+
+ + \ No newline at end of file