3.4.2 Popcorn Hacks

song_title = "drivers license"  
first_verse = "I got my drivers license last week Just like we always talked about Cause you were so excited for me To finally drive up to your house"
second_verse = "youre probably with that blonde girl that always made me doubt she is so much older than me she is everything i am insecure about"
last_verse = "red lights stop signs i still see ur face in the whhite cars front yards cant drive past the places we used to go bc i still love you"
lyrics = "I got my drivers license last week Just like we always talked about Cause you were so excited for me To finally drive up to your house youre probably with that blonde girl that always made me doubt she is so much older than me she is everything i am insecure about red lights stop signs i still see ur face in the whhite cars front yards cant drive past the places we used to go bc i still love you"
lyrics = lyrics.split()
title_count = 0 
for lyric in lyrics:
	if lyric == "drivers":
		title_count += 1

index_50 = lyrics[49]
first_verse = last_verse
my_song = first_verse + second_verse

print(title_count)
print(index_50)
print(my_song)
1
am
red lights stop signs i still see ur face in the whhite cars front yards cant drive past the places we used to go bc i still love youyoure probably with that blonde girl that always made me doubt she is so much older than me she is everything i am insecure about

3.4.3 Popcorn Hacks

const flower = "Rose";
const animal = "Tiger";
const newCreature = `${flower}${animal}`; 

console.log(`Meet the new creature: ${newCreature}!`);

const creatureName = newCreature;
const location = "the enchanted forest";
const characterName = "Lila";
const creatureDescription = "with beautiful petals and fierce stripes.";

const story = `
In ${location}, there lived a creature named ${creatureName}, 
a unique being ${creatureDescription} 

One sunny day, ${characterName}, a curious girl, wandered into the forest. 
She exclaimed, 'Wow! I've never seen anything like you! What are you?'

The ${creatureName} replied, 'I am a RoseTiger, the guardian of this forest. 
I protect the flowers and the animals that live here.'

Intrigued, ${characterName} asked, 'Can you show me your home?'
'Of course!' said the ${creatureName}. 'Follow me, and I'll show you the most beautiful flowers you've ever seen!'

Together, they ventured deeper into the forest, discovering a world full of color and life. 
From that day on, ${characterName} and the ${creatureName} became the best of friends, 
exploring the enchanted forest together.
`;

console.log(story);

3.4.4 Homework Hacks

function analyzeText(text) {
    const wordCount = text.split(/\s+/).length;
    const charCount = text.length; 
    const sentenceCount = text.split(/[.!?]/).filter(Boolean).length;
    const averageWordLength = charCount / wordCount; 
    return {
        wordCount,
        charCount,
        sentenceCount,
        averageWordLength: averageWordLength.toFixed(2) 
    };
}

function replaceWords(originalText) {
    let modifiedText = originalText;

    while (true) {
        const wordToReplace = prompt("Enter the word you want to replace (or type 'exit' to finish):");
        
        if (wordToReplace === 'exit') {
            break;
        }

        const replacementWord = prompt(`Enter the replacement for '${wordToReplace}':`);
        
        modifiedText = modifiedText.replace(new RegExp(`\\b${wordToReplace}\\b`, 'g'), replacementWord);
        console.log(`Modified text: ${modifiedText}`);
    }

    return modifiedText;
}

const userInput = prompt("Enter a sentence or paragraph for analysis:");
const analysisResult = analyzeText(userInput);

console.log("Text Analysis:");
console.log(`Word Count: ${analysisResult.wordCount}`);
console.log(`Character Count: ${analysisResult.charCount}`);
console.log(`Sentence Count: ${analysisResult.sentenceCount}`);
console.log(`Average Word Length: ${analysisResult.averageWordLength} characters`);

const modifiedText = replaceWords(userInput);
console.log("Final modified text:", modifiedText);