JavaScript by Tomar Ravi;Dangi Sarishma;

JavaScript by Tomar Ravi;Dangi Sarishma;

Author:Tomar, Ravi;Dangi, Sarishma; [Tomar, Ravi]
Language: eng
Format: epub
Tags: COMPUTERS/Programming/Games, COMPUTERS/Programming/General, COMPUTERS/Programming Languages/General, COMPUTERS/Programming Languages/JavaScript, COMPUTERS/Web/General, COMPUTERS/Web/Site Design, COMPUTERS/Web/Web Programming
Publisher: CRC Press LLC
Published: 2022-11-15T00:00:00+00:00


5.10.3.3 Code Snippet-3

// Create reference to button.

const btn = document.querySelector(".btn");

// Creating a reference to input box.

const myInput = document.querySelector("#thought");

// Create a reference to where result is to be displayed.

const resultHere = document.querySelector(".result p");

btn.addEventListener("click", () => {

const processPrompt = document.createElement("p");

processPrompt.innerHTML = "Doing this now…";

processPrompt.style.color = "red";

var content =

"Splitting a string (your lyrics) into array of string-chunks, based on a delimiter (white-space)";

var comment = document.createElement("p");

comment.innerHTML = content;

resultHere.appendChild(processPrompt);

resultHere.appendChild(comment);

const lyrics = myInput.value;

// Splitting the lyrics into separate words.

const chunks = lyrics.split(" ");

// Convert array into string, for displaying purpose.

const result = document.createElement("p");

result.innerHTML = `[ ${chunks.toString()}]`;

// Display result.

resultHere.appendChild(result);

});



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.