String and string method exercises

Exercise 1
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var txt = "Hello World";
document.getElementById("demo").innerHTML = txt.indexOf("World");
</script>

</body>
</html>


Exercise2
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var str = "Apple,Banana,Kiwi";
document.getElementById("demo").innerHTML = str.slice(6);
</script>

</body>
</html>

Exercise 3
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var txt = "Hello World";
document.getElementById("demo").innerHTML = txt.replace("World", "Universe");
</script>

</body>
</html>

Exercise 4
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var txt = "Hello World";
document.getElementById("demo").innerHTML = txt.toUpperCase();
</script>

</body>
</html>

Exercise 5
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var txt = "Hello World";
document.getElementById("demo").innerHTML = txt.toLowerCase();
</script>

</body>
</html>

Exercise 6
<!DOCTYPE html>
<html>
<body>

<p id="demo">Display the result here.</p>

<script>
var str1 = "Hello ";
var str2 = "World!";
document.getElementById("demo").innerHTML = str1.concat(str2);
</script>

</body>
</html>

No comments:

Post a Comment