0% found this document useful (0 votes)
3 views3 pages

1

The document contains JavaScript code snippets that perform various tasks, including reversing a number and a string, checking if a string is a palindrome, counting character occurrences in a string, and finding the longest word in a sentence. Each task is implemented using loops and conditionals, with user input gathered through prompts. The results of these operations are logged to the console.

Uploaded by

ymathsdoubt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

1

The document contains JavaScript code snippets that perform various tasks, including reversing a number and a string, checking if a string is a palindrome, counting character occurrences in a string, and finding the longest word in a sentence. Each task is implemented using loops and conditionals, with user input gathered through prompts. The results of these operations are logged to the console.

Uploaded by

ymathsdoubt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

var num = prompt("enter the number:")

var find = 0;

var len = num.toString().length;

for(var i = len-1; i>=0 ; i--){

var check = parseInt(num.toString()[i]);

find = find * 10 + check ;

console.log(find)

var str = prompt("enter the number:")

var find = ""

var len = str.length;

for(var i = len-1; i>=0 ; i--){

find+= str[i] ;

console.log(find)

var str = prompt("enter the number:");

var find = ""

var len = str.length;

for(var i = len-1; i>=0 ; i--){

find+= str[i] ;

if(str == find){
console.log("palindrome");

else{

console.log("not a palindrome");

var str = prompt("Enter the string:");

var count ={};

for(var char of str){

if(count[char]){

count[char]++;

else {

count[char]=1

console.log(count);

var str = prompt("enter the sentence:")

var words = str.split(' ');

var longest="";

for(var word of words){

if(word.length>longest.length){

longest = word;

}
console.log(longest);

You might also like