Search This Blog

Thursday, 28 July 2016

How to guess the paragraph last word is true or false using javascript?

Html page:

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

Javascript page:

<script>
function myFunction()
 {
    var str = "Hello world, welcome to the universe.";
    var n = str.endsWith("to");
    document.getElementById("demo").innerHTML = n;
}
</script>

Output:

True

No comments:

Post a Comment