diff --git a/app.js b/app.js index ab3ad10..81fb025 100644 --- a/app.js +++ b/app.js @@ -1,26 +1,111 @@ // 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. +// - 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) + " "); + } + } + 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"); +} // 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 // 3.1 Print all the characters of the driver's name, separated by a space and in capitals i.e. "ProGrad" @@ -53,4 +138,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..43551c4 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + + js practise lab + + + + + + + + \ No newline at end of file