Skip to content

Commit 3f74be2

Browse files
committed
Final javascript projects
1 parent 82b7380 commit 3f74be2

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function rot13(str) {
2+
str = str.toUpperCase();
3+
var newStr = "";
4+
for (let i=0; i < str.length; i++){
5+
if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90){
6+
//console.log(str.charCodeAt(i));
7+
var newCode = str.charCodeAt(i)+13;
8+
if (newCode > 90){
9+
newCode = newCode - 90 + 64;
10+
}
11+
//console.log(newCode)
12+
var newLetter = String.fromCharCode(newCode);
13+
//console.log(str.charAt(i))
14+
newStr+=newLetter;
15+
}
16+
else newStr+=str.charAt(i);
17+
}
18+
19+
return newStr
20+
21+
}
22+
23+
rot13("SERR PBQR PNZC");
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function palindrome(str) {
2+
var regexPattern = /[^A-Za-z0-9+]/g;
3+
var newStr = (str.replace(regexPattern, "")).toLowerCase();
4+
var palStr = newStr.split("").reverse().join("");
5+
if (newStr == palStr)
6+
return true;
7+
else return false;
8+
}
9+
10+
palindrome('eye');
11+
12+
/***
13+
let str = prompt("Please enter a string: ");
14+
palindrome(str);
15+
***/
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function convertToRoman(num) {
2+
var romanNum = "";
3+
while(num>0){
4+
if (num >=1000){
5+
romanNum+="M";
6+
num-=1000;
7+
}
8+
else if (num >= 900){
9+
romanNum+="CM";
10+
num-=900;
11+
}
12+
else if (num >= 500){
13+
romanNum+="D";
14+
num-=500;
15+
}
16+
else if (num >= 400){
17+
romanNum+="CD";
18+
num-=400;
19+
}
20+
else if (num >= 100){
21+
romanNum+="C";
22+
num-=100;
23+
}
24+
else if (num >= 90){
25+
romanNum+="XC";
26+
num-=90;
27+
}
28+
else if (num >= 50){
29+
romanNum+="L";
30+
num-=50;
31+
}
32+
else if (num >= 40){
33+
romanNum+="XL";
34+
num-=40;
35+
}
36+
else if (num >= 10){
37+
romanNum+="X";
38+
num-=10;
39+
}
40+
else if (num >= 9){
41+
romanNum+="IX";
42+
num-=9;
43+
}
44+
else if (num >= 5){
45+
romanNum+="V";
46+
num-=5;
47+
}
48+
else if (num >= 4){
49+
romanNum+="IV";
50+
num-=4;
51+
}
52+
else {
53+
romanNum+="I";
54+
num-=1;
55+
}
56+
}
57+
return romanNum;
58+
}
59+
60+
convertToRoman(36);

0 commit comments

Comments
 (0)