1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
atroni [7]
3 years ago
6

4.Write a JavaScript program to find if a given word is a palindrome or not. Word is given by user via prompt command.

Computers and Technology
1 answer:
ad-work [718]3 years ago
4 0

Answer:

Here is the JavaScript program:

function Palindrome(word) {

   return word == word.toLowerCase().split("").reverse().join("") ? true : false; }

inputWord = prompt("Enter a word to check its if its palindrome or not?");  

alert(Palindrome(inputWord));

Explanation:

The function Palindrome takes a word as argument.

 return word == word.toLowerCase().split("").reverse().join("") ? true : false; }

This statement first converts the word, which is a string to lower case letters using toLowerCase() method. Next split() method splits the word string into an array of strings, then reverse() method reverses the this array and join() method joins all the elements of the array back to the string. At last the conditional statement checks if the resultant string (reverse of word) is equal  to the original word (that was input by user). If both the word and its reverse are equal/same then the program outputs true otherwise returns false.

inputWord = prompt("Enter a word to check its if its palindrome or not?");   statement uses prompt command to take input from the user. inputWord holds the word that user enters.

alert(Palindrome(inputWord)); statement calls Palindrome() method by passing the inputWord (word entered by user) to check if the input word is a palindrome or not. alert() method displays an alert box ( a message) with true if the inputWord is a palindrome otherwise it displays false.

You might be interested in
How many permutations for a 7 characters in length string, which contains all following letters R, X, S, Y, T, Z, U, has either
True [87]

Answer:

Following are the solution to this question:

Explanation:

In the following forms, RXS can appear:  

R X S \_ \_ \_  \_ it may look like that really, 4 \times 3  \times 2  \times 1 forms = 24 may construct the remainder of its letters.  

\_ R X S  \_ \_  \_ it may look like that really,  4 \times 3  \times 2  \times 1 forms = 24 may construct the remainder of its letters.  

\_  \_  R X S \_  \_ it may look like that really, 4 \times 3  \times 2  \times 1 forms = 24 may construct the remainder of its letters.  

\_ \_ \_  R X S \_ it may look like that really,  4 \times 3  \times 2  \times 1 forms = 24 may construct the remainder of its letters.  

\_ \_ \_ \_ R X S it may look like that really,  4 \times 3  \times 2  \times 1 forms = 24 may construct the remainder of its letters.  

And we'll have a total of 24 \times 5 = 120 permutations with both the string RXS.

In the following forms, UZ can appear:

U Z \_ \_ \_ \_\ _  They can organize your remaining 5 characters through 5 categories! Procedures = 5 \times 4 \times  3 \times 2 \times 1 = 120

\_ UZ \_ \_ \_ \_ They can organize your remaining 5 characters through 5 categories! Procedures = 5 \times 4 \times  3 \times 2 \times 1 = 120

\_ \_ U Z \_ \_ \_They can organize your remaining 5 characters through 5 categories! Procedures  = 5 \times 4 \times  3 \times 2 \times 1 = 120

\_ \_ \_ U Z \_ \_They can organize your remaining 5 characters through 5 categories! Procedures  = 5 \times 4 \times  3 \times 2 \times 1 = 120

\_ \_ \_ \_ U Z  \_ They can organize your remaining 5 characters through 5 categories! Procedures  = 5 \times 4 \times  3 \times 2 \times 1 = 120

\_ \_ \_  \_ \_ U Z They can organize your remaining 5 characters through 5 categories! Procedures  = 5 \times 4 \times  3 \times 2 \times 1 = 120

There may be 120 \times 6 = 720 ways of complete permutations.

5 0
3 years ago
interpret the following SQL create table persons (person I'd int, last name varchar (255) first name varchar (255) address varch
zhuklara [117]

Answer:

Kindly check explanation

Explanation:

The SQL statement above could be interpreted as follows :

create table command is used to create a table named 'persons' with five columns which are labeled :

person I'd : whose data type is an integer

last name column with a variable character data type with maximum length of 255

first name column with a variable character data type with maximum length of 255

address column with a variable character data type with maximum length of 255

city column with a variable character data type with maximum length of 255

The VARCHAR data type is ideal since we expect the column values to be of variable length.

3 0
3 years ago
I need an If else statement that sorts three numbers from a file from least to greatest
Vera_Pavlovna [14]
Void sort3(int& a, int& b, int& c)
{
if (a > b)
{
std::swap(a, b);
}
if (b > c)
{
std::swap(b, c);
}
if (a > b)
{
std::swap(a, b);
}
}
5 0
2 years ago
Which of the following is not true about designing classes? In order for class information to be printed instead of a memory add
Leokris [45]
'<span>All methods should be declared private</span>' is not true for classes. One should be able to change the properties of objects, and to do this safely and in a controlled manner, some public methods are declared. Some private methods can also be declared for more potentially sensitive operations for being called from within the class. 
6 0
3 years ago
C++ Code Outputs.
mojhsa [17]

Answer:

#include

#include

#include

#include

using namespace std;

struct courseInfo{

string name;

int unit;

char grade;

};

struct Student {

string fName;

string lName;

string idNumber;

courseInfo courses[2];

int unitCompleted;

double gpa;

};

Student s;

bool openFile(ifstream &in);

void Print_info_one(Student s);

void Read_info(Student &s);

float Find_points(char c) ;

bool openFile(ifstream &inFile){

string line;

int i=0,k=0;

string fName="", lname="", id="", name1="", name2="";

char grade1, grade2;

int unit1, unit2;

if (inFile.is_open())

{

while (getline(inFile, line))

{

while (line[i] != ',')

{

fName += line[i];

i++;

}

i++;

i++;

while (line[i] != ' ')

{

lname += line[i];

i++;

}

i++;i++;

while (line[i] != ' ')

{

id += line[i];

i++;

}

i++;

int count=0;

while (count <2)

{

name1 += line[i];

i++;

if(line[i] == ' ' ) count++;

}

i++;

grade1 = line[i];

i++;i++;

unit1 = line[i]-'0';

i++;i++;

count=0;

while (count <2)

{

name2 += line[i];

i++;

if(line[i] == ' ' ) count++;

}

i++;

grade2 = line[i];

i++;i++;

unit2 = line[i]-'0';

}

inFile.close();

s.fName = fName;

s.lName = lname;

s.idNumber = id;

s.courses[0].name = name1;

s.courses[0].grade = grade1;

s.courses[0].unit = unit1;

s.courses[1].name = name2;

s.courses[1].grade = grade2;

s.courses[1].unit = unit2;

s.unitCompleted = unit1 + unit2;

s.gpa = (unit1*Find_points(grade1) + unit2*Find_points(grade2))/(unit1+unit2);

}

else

{

cout << "Error reading file\n";

return false;

}

return true;

}

void Print_info_one(Student s){

cout << "Name: " << s.fName << ", " << s.lName << " ID Number: " << s.idNumber << " Course 1 Name: " << s.courses[0].name << " Grade: "

<< s.courses[0].grade << " Units: " << s.courses[0].unit << " Course 2 Name: " << s.courses[1].name << " Grade: "

<< s.courses[1].grade << " Units: " << s.courses[1].unit << " Unit completed: " << s.unitCompleted << " GPA:" << s.gpa << endl;

}

void Read_info(Student &s){

}

float Find_points(char grade){

switch (grade)

{

case 'A':

return 4.0;

break;

case 'B':

return 3.0;

break;

case 'C':

return 2.0;

break;

case 'D':

return 1.0;

break;

case 'F':

return 0;

break;

default:

break;

}

return 0;

}

int main() {

ifstream inFile;

std::fstream fs;

fs.open ("input.txt", std::fstream::in );

Print_info_one(s);

return 0;

Explanation:

5 0
3 years ago
Other questions:
  • You will use the _____
    15·2 answers
  • Write a function statement() that takes as input a list of floating-point numbers, with positive numbers representing deposits t
    8·1 answer
  • Can anyone drink and drive safely?
    13·2 answers
  • On a Linux system, which command allows you to modify settings used by the built-in packet filtering firewall?
    15·1 answer
  • Write a Java class called getName that prompts a user for their name and then displays "Hello, [name here]!" The flow should loo
    14·1 answer
  • Which is true about POP3 and IMAP for incoming email?
    14·1 answer
  • Convert the following denary numbers into
    14·1 answer
  • Aside from human user types, there are nonhuman user groups. Known as account types, __________ are implemented by the system to
    10·1 answer
  • Select the correct answer from each drop down menu
    11·1 answer
  • The ________ is specifically designed for situations requiring a counter variable to control the number of times a loop iterates
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!