For each problem, use a java scripting on the problem and put the number assigned problem followed by whatever output the task requires. Output a blank line between problems. 1.the user to enter a two words for this problem. a. Print the shorter word (the one with fewer characters), followed by the longer word. b. Print the words in alphabetical order.
For each problem, use a java scripting on the problem and put the number assigned problem followed by whatever output the task requires. Output a blank line between problems.
1.the user to enter a two words for this problem.
a. Print the shorter word (the one with fewer characters), followed by the longer word.
b. Print the words in alphabetical order.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let x=window.prompt("Enter first string");
let y=window.prompt("Enter second string");
if (x.length<y.length) {
let arr=[];
let i=0;
while(i<x.length)
{
arr[i]=x[i];
i=i+1;
}
document.getElementById("demo").innerHTML = arr.sort();
}
else{
let arr=[];
let i=0;
while(i<y.length)
{
arr[i]=y[i];
i=i+1;
}
document.getElementById("demo").innerHTML = arr.sort();
}
</script>
</body>
</html>
Step by step
Solved in 2 steps