Skip to content

Commit 9598167

Browse files
author
Devendra Parmar
committed
Solved the two questions of the JavaScript
1. Check the number fraction is proper or improper 2. Change the characters in String like a with z, b with y and c with x
1 parent 2ba1079 commit 9598167

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

ChangeTheCharactersInAString.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Write a JavaScript program to change the characters (lower case) in a string where a turns into z, b turns into y, c turns into x, ..., n turns into m, m turns into n, ..., z turns into a.
2+
3+
const prompt = require("prompt-sync")();
4+
5+
console.log("Enter The String Here : ");
6+
var str = prompt();
7+
8+
var result = [];
9+
10+
for (let i = 0; i < str.length; i++) {
11+
var charOrder = str.charCodeAt(i) - "a".charCodeAt(0);
12+
var changeChar = 25 - charOrder + "a".charCodeAt(0);
13+
result.push(String.fromCharCode(changeChar));
14+
}
15+
16+
console.log(result.join(""));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Write a JavaScript program to check whether a given fraction is proper or not.
2+
3+
// Note: There are two types of common fractions, proper or improper. When the numerator and the denominator are both positive, the fraction is called proper if the numerator is less than the denominator, and improper otherwise.
4+
5+
const prompt = require("prompt-sync")();
6+
7+
console.log("Enter Array Size : ");
8+
var size = parseInt(prompt());
9+
10+
var arr = [];
11+
12+
console.log("Enter Array Elements : ");
13+
for (let i = 0; i < size; i++) {
14+
console.log(`[${i}] : `);
15+
var elem = parseInt(prompt());
16+
arr.push(elem);
17+
}
18+
19+
var div = Math.abs(arr[0] / arr[1]);
20+
21+
if (div < 1) {
22+
console.log("Proper Fraction!");
23+
} else {
24+
console.log("Improper Fraction!");
25+
}

0 commit comments

Comments
 (0)