From 22ee22f51f4722d0850432ce78b0ff8fb5fff972 Mon Sep 17 00:00:00 2001 From: kenanqafarov Date: Wed, 20 May 2026 17:54:39 +0400 Subject: [PATCH] Solved lab --- index.js | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/index.js b/index.js index 6b0fec3ad..2814beb6b 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,127 @@ + +let hacker1 = "Kenan"; +let hacker2 = "Elchin"; + // Iteration 1: Names and Input +const firstIteration = (hacker1,hacker2) => { +console.log(`The driver's name is ${hacker1}`); +console.log(`The navigator's name is ${hacker2}`); +} +firstIteration(hacker1,hacker2); + // Iteration 2: Conditionals +const secondIteration = (hacker1,hacker2) =>{ + if (hacker1.length > hacker2.length) { + console.log(`The driver has the longest name, it has ${hacker1.length} characters.`); + } else if (hacker1.length < hacker2.length) { + console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`); + } else { + console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`); + } +} + +secondIteration(hacker1,hacker2); + + + // Iteration 3: Loops + +const thirdIteration = (hacker1,hacker2) => { + let result = ""; + for (let i = 0; i < hacker1.length; i++) { + if(i === hacker1.length - 1) { + result += hacker1[i].toUpperCase(); + } else { + result += hacker1[i].toUpperCase() + " "; + } + } + + let reversed = ""; + for (let i = hacker2.length - 1; i >= 0; i--) { + reversed += hacker2[i]; + } + + // Ask this part + console.log(result); + console.log(reversed); + + if(hacker1>hacker2){ + console.log("The driver's name goes first."); + } else if(hacker1 { + let wordCount = 0; + let etCount = 0; + let insideWord = false; + let currentWord = ""; + + for (const char of longText) { + if (char !== " " && char !== "\n" && char !== "\t") { + currentWord += char; + if (!insideWord) { + wordCount++; + insideWord = true; + } + + } + else { + + if(currentWord === "et") { + etCount++; + } + currentWord =""; + insideWord = false; + } + } + console.log(wordCount); + console.log(etCount); +} +wordCounter(longText); + +// Bonus 2: Palindrome + +const phraseToCheck = "A man, a plan, a canal: Panama"; +const isPalindrome = (phrase)=>{ + + let cleanedPhrase = ""; + let reversedPhrase = ""; + + for (const char of phrase) { + if(char!==" " && char !== "," && char !== ":" && char !== ".") { + cleanedPhrase += char; + reversedPhrase = char + reversedPhrase; + } + } + + if(cleanedPhrase.toLowerCase() == reversedPhrase.toLowerCase()) { + console.log("It's a palindrome!"); + }else{ + console.log("It's not a palindrome."); + } +} + + +isPalindrome(phraseToCheck); \ No newline at end of file