Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Html/Javascript Only (Writing the Word Equivalent of a Check Amount) Continuing

ID: 3599800 • Letter: H

Question

Html/Javascript Only

(Writing the Word Equivalent of a Check Amount) Continuing the discussion in the preceding exercise, we reiterate the importance of designing check-writing systems to prevent alteration of check amounts. One common security method requires that the check amount be both written in numbers and spelled out in words. Even if someone is able to alter the numerical amount of the check, it’s extremely difficult to change the amount in words. Many computerized check-writing systems do not print the amount of the check in words. Perhaps the main reason for this omission is that most high-level languages used in commercial applications do not contain adequate string-manipulation features. Another reason is that the logic for writing word equivalents of check amounts is somewhat involved.

Write a script that inputs a numeric check amount and writes the word equivalent of the amount.

For example, the amount 112.43 should be written as

ONE HUNDRED TWELVE and 43/100

Explanation / Answer

SOURCE CODE:
<html>
<head>
<title>Number to Word</title>
</head>
<body>
<input type="text" name="nob" placeholder="Amount on Check" />
<div id="word">
</div>
<script>
function numToWrd(amt) {
var digits = new Array();
digits[0] = '';
digits[1] = 'One';
digits[2] = 'Two';
digits[3] = 'Three';
digits[4] = 'Four';
digits[5] = 'Five';
digits[6] = 'Six';
digits[7] = 'Seven';
digits[8] = 'Eight';
digits[9] = 'Nine';
digits[10] = 'Ten';
digits[11] = 'Eleven';
digits[12] = 'Twelve';
digits[13] = 'Thirteen';
digits[14] = 'Fourteen';
digits[15] = 'Fifteen';
digits[16] = 'Sixteen';
digits[17] = 'Seventeen';
digits[18] = 'Eighteen';
digits[19] = 'Nineteen';
digits[20] = 'Twenty';
digits[30] = 'Thirty';
digits[40] = 'Forty';
digits[50] = 'Fifty';
digits[60] = 'Sixty';
digits[70] = 'Seventy';
digits[80] = 'Eighty';
digits[90] = 'Ninety';
amt = amt.toString();
var tempo = amt.split(".");
var nob = tempo[0].split(",").join("");
var lnt = nob.length;
var str = "";
if (lnt <= 9) {
var arr = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);
var arr1 = new Array();
for (var p = 0; p < lnt; p++) {
arr1[p] = nob.substr(p, 1);
}
for (var p = 9 - lnt, q = 0; p < 9; p++, q++) {
arr[p] = arr1[q];
}
for (var p = 0, q = 1; p < 9; p++, q++) {
if (p == 0 || p == 2 || p == 4 || p == 7) {
if (arr[p] == 1) {
arr[q] = 10 + parseInt(arr[q]);
arr[p] = 0;
}
}
}
value = "";
for (var p = 0; p < 9; p++) {
if (p == 0 || p == 2 || p == 4 || p == 7) {
value = arr[p] * 10;
} else {
value = arr[p];
}
if (value != 0) {
str += digits[value] + " ";
}
if ((p == 1 && value != 0) || (p == 0 && value != 0 && arr[p + 1] == 0)) {
str += "Crores ";
}
if ((p == 3 && value != 0) || (p == 2 && value != 0 && arr[p + 1] == 0)) {
str += "Lakhs ";
}
if ((p == 5 && value != 0) || (p == 4 && value != 0 && arr[p + 1] == 0)) {
str += "Thousand ";
}
if (p == 6 && value != 0 && (arr[p + 1] != 0 && arr[p + 2] != 0)) {
str += "Hundred and ";
} else if (p == 6 && value != 0) {
str += "Hundred ";
}
}
str = str.split(" ").join(" ");
}
return str;
}
</script>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote