From 6bec5a878fe97c0274264295979ed2455204fb0a Mon Sep 17 00:00:00 2001 From: Amarthya Date: Tue, 17 Mar 2020 12:54:57 +0530 Subject: [PATCH 1/2] commit --- app.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- index.html | 15 +++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index ab3ad10..b733316 100644 --- a/app.js +++ b/app.js @@ -1,25 +1,98 @@ // 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; +ProGrad_1 = "driver"; +document.write("The driver's name is " + ProGrad_1); +ProGrad_2 = "navigator"; +document.write("
"); +document.write("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 d, n; +d = ProGrad_1.length; +n = ProGrad_2.length; +if (d > n) { + document.write("
"); + document.write("The driver has the longest name, it has " + d + "characters"); +} else if (d < n) { + document.write("
"); + document.write("The navigator has the longest name, it has " + n + " characters"); + +} else { + document.write("
"); + document.write("Wow, you both have equally long names, " + n + "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. +var a = "ProGrad"; +var i; +if (a.match(/[aeiouAEIOU]/)) { + document.write("
"); + document.write(a + " "); + b = a.length; + for (i = 0; i < b; i++) { + if (a.charAt(i) == 'a' || a.charAt(i) == 'e' || a.charAt(i) == 'i' || a.charAt(i) == 'o' || a.charAt(i) == 'u' || a.charAt(i) == 'A' || a.charAt(i) == 'E' || a.charAt(i) == 'I' || a.charAt(i) == 'O' || a.charAt(i) == 'U') { + document.write(a.charAt(i) + " "); + } + } +} else { + document.write("
"); + document.write("no vowels"); +} + + + + // 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 +var count = 0; +var countlow = 0; + +if ((a >= 'A' && a <= 'Z') || (a >= 'a' && a <= 'z')) { + document.write("
"); + document.write("string contains uppercase and lowercase characters"); +} else { + document.write("
"); + document.write("string does not contains uppercase and lowercase characters"); +} + +for (i = 0; i < b; i++) { + if (a.charAt(i) >= 'A' && a.charAt(i) <= 'Z') + count++; +} +document.write("
"); +document.write("the number of uppercase characters are " + count); +for (i = 0; i < b; i++) { + if (a.charAt(i) >= 'a' && a.charAt(i) <= 'z') + countlow++; +} +document.write("
"); +document.write("the number of lowercase characters are " + countlow); + + + + + + + + + + // Progression 3: Control Statements - 2 @@ -53,4 +126,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' \ No newline at end of file diff --git a/index.html b/index.html index e69de29..43551c4 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + + js practise lab + + + + + + + + \ No newline at end of file From 3f2213eb68cc4f878021c7c584894b4d9dd34b1f Mon Sep 17 00:00:00 2001 From: Amarthya Date: Tue, 17 Mar 2020 13:35:26 +0530 Subject: [PATCH 2/2] newcommit --- app.js | 94 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/app.js b/app.js index b733316..81fb025 100644 --- a/app.js +++ b/app.js @@ -22,79 +22,91 @@ let d, n; d = ProGrad_1.length; n = ProGrad_2.length; if (d > n) { - document.write("
"); - document.write("The driver has the longest name, it has " + d + "characters"); + document.write("
"); + document.write("The driver has the longest name, it has " + d + "characters"); } else if (d < n) { - document.write("
"); - document.write("The navigator has the longest name, it has " + n + " characters"); - + document.write("
"); + document.write( + "The navigator has the longest name, it has " + n + " characters" + ); } else { - document.write("
"); - document.write("Wow, you both have equally long names, " + n + "characters!"); + document.write("
"); + document.write("Wow, you both have equally long names, " + n + "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. var a = "ProGrad"; var i; if (a.match(/[aeiouAEIOU]/)) { - document.write("
"); - document.write(a + " "); - b = a.length; - for (i = 0; i < b; i++) { - if (a.charAt(i) == 'a' || a.charAt(i) == 'e' || a.charAt(i) == 'i' || a.charAt(i) == 'o' || a.charAt(i) == 'u' || a.charAt(i) == 'A' || a.charAt(i) == 'E' || a.charAt(i) == 'I' || a.charAt(i) == 'O' || a.charAt(i) == 'U') { - document.write(a.charAt(i) + " "); - } + document.write("
"); + document.write(a + " "); + b = a.length; + for (i = 0; i < b; i++) { + if ( + a.charAt(i) == "a" || + a.charAt(i) == "e" || + a.charAt(i) == "i" || + a.charAt(i) == "o" || + a.charAt(i) == "u" || + a.charAt(i) == "A" || + a.charAt(i) == "E" || + a.charAt(i) == "I" || + a.charAt(i) == "O" || + a.charAt(i) == "U" + ) { + document.write(a.charAt(i) + " "); + } + } + for (i = 0; i < b; i++) { + if ( + a.charAt(i) == "a" || + a.charAt(i) == "e" || + a.charAt(i) == "i" || + a.charAt(i) == "o" || + a.charAt(i) == "u" || + a.charAt(i) == "A" || + a.charAt(i) == "E" || + a.charAt(i) == "I" || + a.charAt(i) == "O" || + a.charAt(i) == "U" + ) { + document.write(i + " "); } + } } else { - document.write("
"); - document.write("no vowels"); + document.write("
"); + document.write("no vowels"); } - - - // 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 var count = 0; var countlow = 0; -if ((a >= 'A' && a <= 'Z') || (a >= 'a' && a <= 'z')) { - document.write("
"); - document.write("string contains uppercase and lowercase characters"); +if ((a >= "A" && a <= "Z") || (a >= "a" && a <= "z")) { + document.write("
"); + document.write("string contains uppercase and lowercase characters"); } else { - document.write("
"); - document.write("string does not contains uppercase and lowercase characters"); + document.write("
"); + document.write("string does not contains uppercase and lowercase characters"); } for (i = 0; i < b; i++) { - if (a.charAt(i) >= 'A' && a.charAt(i) <= 'Z') - count++; + if (a.charAt(i) >= "A" && a.charAt(i) <= "Z") count++; } document.write("
"); document.write("the number of uppercase characters are " + count); for (i = 0; i < b; i++) { - if (a.charAt(i) >= 'a' && a.charAt(i) <= 'z') - countlow++; + if (a.charAt(i) >= "a" && a.charAt(i) <= "z") countlow++; } document.write("
"); document.write("the number of lowercase characters are " + countlow); - - - - - - - - - - - // 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" @@ -126,4 +138,4 @@ document.write("the number of lowercase characters are " + countlow); // "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' \ No newline at end of file +// 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'