Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Level 11 and lesson 2

(i was not not getting any help) check this code and help me

<!doctype html>
<html>
<head>
<title>JS String Operations</title>
<style>
input {
padding: 10px;
width: 300px;
}

#btn {
background-color: #4535AA;
color: white;
border: 0;
border-radius: 5px;
padding: 10px 5px;
cursor: pointer;
}
</style>
</head>
<body>

</p>
<div><input type="text" id="searchData"/></div>
<br/>
<button id="btn" onclick="findme()">Find Keyword!</button>
<button id="btn" onclick="count()">Count Words</button>
<br/>
<div id="result"></div>
<script>
function findme() {
// get value from input field
let inputStr = document.getElementById(" ").value;
if(inputStr==' ') {
alert("Nothing to find");
return;
}
// change text to lowercase
inputStr = inputStr.lowercase();
let content = document.getElementById("content").innerText;
// change text to lowercase
content = content.lowercase();
// look for the inputStr in content
if(content.search("content"))
{
alert("String found");
}
else {
alert("String not found");
}
}

function count() {
let content = document.getElementById("content").innerText;
// use string function to create array of its words
let arr = content.split(" ");

let resultDiv = document.getElementById("result");
// use array property to find number of array elements
resultDiv = console.log("Number of words:" + arr.length);
}
</script>
</body>
</html>
by

2 Answers

SaravananRajendran

<script>

function findme() {
// get value from input field
let inputStr = document.getElementById("searchData").value;

if (inputStr == null || inputStr ==""){
alert("Nothing to find");
return;
}
// change text to lowercase
inputStr = inputStr.toLowerCase();
let content = document.getElementById("content").innerText;
// change text to lowercase
content = content.toLowerCase();
// look for the inputStr in content

if (content.search(inputStr) >= 0) {
alert("String found");
}
else {
alert("String not found");
}

}

function count() {
let content = document.getElementById("content").innerText;
// use string function to create array of its words
let arr = content.split(" ");

let resultDiv = document.getElementById("result");
// use array property to find number of array elements
resultDiv.textContent= "Number of words:" + arr.length;
// resultDiv.textContent = "Number of words:" + size;
}
</script>
SaravananRajendran
dude it will work try to fix my issues also , i have posted in form already Level 11 , lesson 4

Login / Signup to Answer the Question.