Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Experiment No. 5 Assignment On String Functions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

EXPERIMENT NO.

5
Assignment on String Functions –
1. Develop JavaScript to accept Character from user and convert it into
Unicode. Develop JavaScript to accept Unicode from user and convert it into
character.
2. Develop JavaScript to accept character/word from user, search that
character/word in given string and print its position (Hint – search()).
3. Develop JavaScript to accept character from user and find out the last
occurrence of that character form given string.
CODE:
<!—
Aniket Gholap
30
EXP 5
-->
<!DOCTYPE html>
<html>
<head>
<title> String Functions </title>
<head>
<body>
<script>
// Develop JavaScript code to accept Character from User and
to convert it into Unicode.
var s = prompt(“Enter a Character”);
document.write(“Character Code of &nbsp <b>=” s+ </b>
&nbspis=&nbsp+s.charCodeAt()+”<br/> <br/>”);

// Develop JavaScript code to accept Unicode from User and to


convert it into Character.
var a = prompt(Enter a Unicode);
var res = String.fromCharCode(a);
document.write(“Character of Unicode&nbsp <b>=” +a+
</b>nbspis =&nbsp+res+”<br/> <br/>”);
// Develop JavaScript code to accept Character/Word from user,
search that Character/Word in given String and print its position.
var str = “Welcome to JavaScript tutorial”;
var strw = prompt(“Enter a Word from String ‘Welcome to JavaScript
Tutorial”);
document.write(“String=&nbsp” + str + “<br/>);
document.write(“Character of Unocide&nbsp<b>” + strw
+”</b>&nbspin above string is=&nbsp +str.search(strw)+”<br/>
<br/>”);

// Develop a JavaScript code to accept Character from user and find


out the last occurrence of that character from given string.
var strw2 = prompt(“Enter the word from string ‘Welcome to
JavaScript Tutorial”);
document.write(“String=&nbsp” + str + “<br/>”);
document.write(“Position of Last Occurance of &nbsp<b>”+strw2+”
</b>&nbspin above string is=&nbsp”+str.lastIndexOf(strw2)+<br/>
<br/>”);
</script>
</body>
</html>
----------------------------------------------------------------------------------------------------
OUTPUT:
Question 1:

Question 1:

Question 2:
Question 3:

Overall output of a code:

----------------------------------------------------------------------------------------------------

You might also like