This repository has been archived by the owner on Dec 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase_converter_interface.js
698 lines (656 loc) · 35.4 KB
/
base_converter_interface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/**
* file: base_converter_interface.js
* type: JavaScript
* date: 10_JULY_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
/**
* Make a particular HTML element on the web page whose source code file is base_converter.html invisible (without deleting that element).
*
* @param {String} element_id is assumed to be the id value of an existing HTML element on the web whose source code file is base_converter.html.
*/
function hide_page_element(element_id) {
try {
let web_page_element;
if (arguments.length !== 1) throw "exactly one function argument is required.";
if (typeof element_id !== "string") throw "element_id is required to be a String type value.";
if (element_id.length < 1) throw "element_id is required to be a non-empty string.";
web_page_element = document.getElementById(element_id);
web_page_element.style.display = "none";
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of hide_page_element(element_id): " + exception);
}
}
/**
* Make a particular HTML element on the web page defined by base_converter.html visible rather than hidden.
*
* @param {String} element_id is assumed to be the id value of an existing HTML element on the web page whos source code file is base_converter.html.
*/
function unhide_page_element(element_id) {
try {
let web_page_element;
if (arguments.length !== 1) throw "exactly one function argument is required.";
if (typeof element_id !== "string") throw "element_id is required to be a String type value.";
if (element_id.length < 1) throw "element_id is required to be a non-empty string.";
web_page_element = document.getElementById(element_id);
web_page_element.style.display = "block";
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of unhide_page_element(element_id): " + exception);
}
}
/**
* Generate the name of a particular numeric base in the following format: "[base_name] (base-[base_number])".
*
* @param {Number} cardinality_of_base is assumed to be a base-ten integer which is no smaller than two and no larger than sixteen.
*
* @return {String} the inner HTML component of an option for a base select menu; undefined if an exception to normal functioning occurs.
*/
function get_numeric_base_option_label(cardinality_of_base) {
try {
if (arguments.length !== 1) throw "exactly one function argument is required.";
if (typeof cardinality_of_base !== "number") throw "cardinality_of_base is required to be a Number type value.";
if (cardinality_of_base !== Math.floor(cardinality_of_base)) throw "cardinality_of_base is required to be a whole number.";
if ((cardinality_of_base < 2) || (cardinality_of_base > 16)) throw "cardinality_of_base is required to be no smaller than two and no larger than sixteen.";
if (cardinality_of_base === 2) return "BINARY (base-2)";
if (cardinality_of_base === 3) return "TERNARY (base-3)";
if (cardinality_of_base === 4) return "QUATERNARY (base-4)";
if (cardinality_of_base === 5) return "QUINARY (base-5)";
if (cardinality_of_base === 6) return "SENARY (base-6)";
if (cardinality_of_base === 7) return "SEPTENARY (base-7)";
if (cardinality_of_base === 8) return "OCTAL (base-8)";
if (cardinality_of_base === 9) return "NONARY (base-9)";
if (cardinality_of_base === 10) return "DECIMAL (base-10)";
if (cardinality_of_base === 11) return "UNDECIMAL (base-11)";
if (cardinality_of_base === 12) return "DUODECIMAL (base-12)";
if (cardinality_of_base === 13) return "TRIDECIMAL (base-13)";
if (cardinality_of_base === 14) return "TETRADECIMAL (base-14)";
if (cardinality_of_base === 15) return "PENTADECIMAL (base-15)";
if (cardinality_of_base === 16) return "HEXIDECIMAL (base-16)";
if (true) throw "some unexpected runtime error occurred.";
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of get_numeric_base_option_label(cardinality_of_base): " + exception);
return undefinied;
}
}
/**
* Define a select element whose options are the following natural number bases:
* 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16.
*
* Note that the option whose value is "2" is set to be automatically selected if the application user does not click on the select menu.
*
* @param {String} select_id is assumed to be the id of an existing select HTML element on the corresponding web page.
*
* @return {String} an HTML string which is used to instantiate a select element whose options are the following natural number bases:
* 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16;
* undefined if an exception to normal functioning occurs.
*/
function generate_html_string_for_base_select_menu(select_id) {
try {
let html_string = "", option_value = 0;
if (arguments.length !== 1) throw "exactly one function argument is required.";
if (typeof select_id !== "string") throw "select_id is required to be a String type value.";
if (select_id.length < 1) throw "select_id is required to be a non-empty string.";
html_string += '<' + 'select id="' + select_id + '"' + '>';
html_string += '<' + 'option value="2" selected' + '>' + get_numeric_base_option_label(2) + '<' + '/' + 'option' + '>';
for (option_value = 3; option_value <= 16; option_value += 1) html_string += '<' + 'option value="' + option_value + '"' + '>' + get_numeric_base_option_label(option_value) + '<' + '/' + 'option' + '>';
html_string += '<' + '/' + 'select' + '>';
return html_string;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of generate_html_string_for_base_select_menu(select_id): " + exception);
return undefined;
}
}
/**
* Return the value of the selected menu option of a select menu element.
*
* @param {String} select_menu_identifier is assumed to be the id of an existing select HTML element on the corresponding web page.
*
* @return {String} the value of the selected menu option; undefined if an exception to normal functioning occurs.
*/
function get_selected_menu_option_value(select_menu_identifier) {
try {
let menu_object = {}, options_array = [], selected_option_index = 0, selected_option_object = {}, selected_option_value;
menu_object = document.getElementById(select_menu_identifier);
options_array = menu_object.options;
selected_option_index = menu_object.selectedIndex;
selected_option_object = options_array[selected_option_index];
selected_option_value = selected_option_object.value
return selected_option_value;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of get_selected_menu_option(select_menu_identifier): " + exception);
return undefined;
}
}
/**
* Generate the digit key buttons which are used to enter digits whose base is cardinality_of_base.
*
* For example, if cardinality_of_base is 16, then all sixteen digit key buttons will be generated.
*
* By contrast, if cardinality_of_base is 10, then only the first ten of sixteen digit key buttons will be generated.
*
* The digit key buttons are arranged vertically in descending order (where each digit button is encapsulated inside of its own paragraph element).
*
* @param {Number} cardinality_of_base is assumed to be a base-ten integer which is no smaller than two and no larger than sixteen.
*
* @return {String} the HTML string which is used to substantiate the content of the div element whose id is "input_sequence_digit_keys_div";
* undefined if an exception to normal functioning occurs.
*/
function generate_html_string_for_input_sequence_digit_buttons(cardinality_of_base) {
try {
let html_string = "", p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>', i = 0, hexidecimal_digit_set = "0123456789ABCDEF";
if (arguments.length !== 1) throw "exactly one function argument is required.";
if (typeof cardinality_of_base !== "number") throw "cardinality_of_base is required to be a Number type value.";
if (cardinality_of_base !== Math.floor(cardinality_of_base)) throw "cardinality_of_base is required to be a whole number.";
if ((cardinality_of_base < 2) || (cardinality_of_base > 16)) throw "cardinality_of_base is required to be no smaller than two and no larger than sixteen.";
for (i = 0; i < cardinality_of_base; i += 1) html_string += p0 + '<' + 'input type="button" value="' + hexidecimal_digit_set[i] + '" onclick="append_digit_' + hexidecimal_digit_set[i] + '()"' + '>' + p1;
return html_string;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of generate_html_string_for_input_sequence_digit_buttons(cardinality_of_base): " + exception);
return undefined;
}
}
/**
* Determine whether or not hexidecimal_digit is an element of the following set:
* ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ].
*
* @param {String} hexidecimal_digit is assumed to be an element of the following set:
* ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ].
*
* @return {Boolean} true if hexidecimal is a valid hexidecimal digit as defined above; false otherwise.
*/
function is_valid_hexidecimal_digit(hexidecimal_digit) {
try {
let i = 0, hexidecimal_digit_set = "0123456789ABCDEF";
if (arguments.length !== 1) throw "exactly one function argument is required.";
if (typeof hexidecimal_digit !== "string") throw "hexidecimal_digit is required to be a String type value.";
if (hexidecimal_digit.length !== 1) throw "hexidecimal_digit is required to have a length of exactly one character.";
for (i = 0; i < 16; i += 1) if (hexidecimal_digit === hexidecimal_digit_set[i]) return true;
return false;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of is_valid_hexidecimal_digit(hexidecimal_digit): " + exception);
return false;
}
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append hexidecimal_digit to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*
* @param {String} hexidecimal_digit is assumed to be an element of the following set:
* ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ].
*/
function append_digit(hexidecimal_digit) {
try {
let i = 0, input_sequence_span, old_input_sequence = "", new_input_sequence = "";
if (!is_valid_hexidecimal_digit(hexidecimal_digit)) throw "hexidecimal_digit is required to be an element of the following set: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ].";
input_sequence_span = document.getElementById("input_sequence_span");
old_input_sequence = input_sequence_span.innerHTML;
for (i = 1; i < 8; i += 1) new_input_sequence += old_input_sequence[i];
new_input_sequence += hexidecimal_digit;
input_sequence_span.innerHTML = new_input_sequence;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of append_digit_1(): " + exception);
}
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '0' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_0() {
append_digit('0');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '1' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_1() {
append_digit('1');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '2' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_2() {
append_digit('2');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '3' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_3() {
append_digit('3');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '4' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_4() {
append_digit('4');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '5' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_5() {
append_digit('5');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '6' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_6() {
append_digit('6');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '7' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_7() {
append_digit('7');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '8' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_8() {
append_digit('8');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append '9' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_9() {
append_digit('9');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append 'A' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_A() {
append_digit('A');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append 'B' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_B() {
append_digit('B');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append 'C' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_C() {
append_digit('C');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append 'D' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_D() {
append_digit('D');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append 'E' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_E() {
append_digit('E');
}
/**
* Remove the leftmost character from the inner HTML string of the span HTML element whose id is "input_sequence_span".
*
* Append 'F' to right end of that string (such that the total number of characters enclosed by the input sequence span is always eight).
*/
function append_digit_F() {
append_digit('F');
}
/**
* Set the content displayed inside of the span HTML element whose id is "input_sequence_span" to "00000000".
*/
function initialize_input_sequence_span() {
try {
document.getElementById("input_sequence_span").innerHTML = "00000000";
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of initialize_input_sequence_span(): " + exception);
}
}
/**
* Set the inner HTML of the span element whose id is "input_sequence_span_2" and
* "input_sequence_span_3" to the inner HTML of the span element whose id is "input_sequence_span".
*/
function update_input_sequence_span() {
try {
let input_sequence_span, input_sequence_span_2, input_sequence_span_3;
input_sequence_span = document.getElementById("input_sequence_span");
input_sequence_span_2 = document.getElementById("input_sequence_span_2");
input_sequence_span_3 = document.getElementById("input_sequence_span_3");
input_sequence_span_2.innerHTML = input_sequence_span.innerHTML;
input_sequence_span_3.innerHTML = input_sequence_span.innerHTML;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of update_input_sequence_span_2(): " + exception);
}
}
/**
* Set the content displayed inside of
* the span element whose id is "input_base_span",
* the span element whose id is "input_base_span_2", and
* the span element whose id is "input_base_span_3" to the
* input base option which is currently selected from the list of options
* displayed inside the select HTML element whose id is "input_base_menu".
*/
function update_input_base_span() {
try {
let input_base_value = 0, input_base_span, input_base_span_2, input_base_span_3;
input_base_span = document.getElementById("input_base_span");
input_base_span_2 = document.getElementById("input_base_span_2");
input_base_span_3 = document.getElementById("input_base_span_3");
input_base_value = get_selected_menu_option_value("input_base_menu");
input_base_span.innerHTML = input_base_value;
input_base_span_2.innerHTML = input_base_value;
input_base_span_3.innerHTML = input_base_value;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of update_input_base_span(): " + exception);
}
}
/**
* Set the content displayed inside of the HTML element whose id is "digit_buttons_div"
* to display the digit buttons which correspond with the input base option
* which is currently selected from the list of options displayed inside the select HTML element whose id is "input_base_menu".
*/
function update_digit_buttons_div() {
try {
let input_base_value = 0, digit_buttons_div, digit_buttons_for_selected_base;
digit_buttons_div = document.getElementById("digit_buttons_div");
input_base_value = parseInt(get_selected_menu_option_value("input_base_menu"));
digit_buttons_for_selected_base = generate_html_string_for_input_sequence_digit_buttons(input_base_value);
digit_buttons_div.innerHTML = digit_buttons_for_selected_base;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of update_input_base_span(): " + exception);
}
}
/**
* Set the content displayed inside of the span element whose id is "output_base_span_2"
* to the output base option which is currently selected from the list of options displayed
* inside the select HTML element whose id is "output_base_menu".
*/
function update_output_base_span_2() {
try {
let output_base_value = 0, output_base_span_2;
output_base_span_2 = document.getElementById("output_base_span_2");
output_base_value = get_selected_menu_option_value("output_base_menu");
output_base_span_2.innerHTML = output_base_value;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of update_output_base_span_2(): " + exception);
}
}
/**
* Progress from STEP_0 to STEP_1 of the base converter application's input form (which is substantiated using the web page file named base_converter.html).
*
* Assume that this function is called in response to the event of a button click of the NEXT button displayed inside of the div whose id is "step_0_div".
*
* Submit the input base option which is currently selected from the list of options displayed inside the select HTML element whose id is "input_base_menu".
*
* Display the digit buttons which correspond with the selected input base in the next step.
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function step_0_next() {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "step_0_next() was called at time: " + time_stamp;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
update_input_base_span();
update_digit_buttons_div();
hide_page_element("step_0_div");
unhide_page_element("step_1_div");
}
/**
* Regress from STEP_1 to STEP_0 of the base converter application's input form (which is substantiated using the web page file named base_converter.html).
*
* Assume that this function is called in response to the event of a button click of the BACK button displayed inside of the div whose id is "step_1_div".
*
* Reset the text displayed inside of the span element whose id is "input_sequence_span" to its initial state: 00000000.
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function step_1_back() {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "step_1_back() was called at time: " + time_stamp;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
initialize_input_sequence_span();
hide_page_element("step_1_div");
unhide_page_element("step_0_div");
}
/**
* Progress from STEP_1 to STEP_2 of the base converter application's input form (which is substantiated using the web page file named base_converter.html).
*
* Assume that this function is called in response to the event of a button click of the NEXT button displayed inside of the div whose id is "step_1_div".
*
* Update the input base and input sequence displays inside of the STEP_2 div.
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function step_1_next() {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "step_1_next() was called at time: " + time_stamp;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
update_input_sequence_span();
hide_page_element("step_1_div");
unhide_page_element("step_2_div");
}
/**
* Regress from STEP_2 to STEP_1 of the base converter application's input form (which is substantiated using the web page file named base_converter.html).
*
* Assume that this function is called in response to the event of a button click of the BACK button displayed inside of the div whose id is "step_2_div".
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function step_2_back() {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "step_2_back() was called at time: " + time_stamp;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
initialize_input_sequence_span();
hide_page_element("step_2_div");
unhide_page_element("step_1_div");
}
/**
* Progress from STEP_2 to STEP_3 of the base converter application's input form (which is substantiated using the web page file named base_converter.html).
*
* Assume that this function is called in response to the event of a button click of the NEXT button displayed inside of the div whose id is "step_2_div".
*
* Submit the output base option which is currently selected from the list of options displayed inside the select HTML element whose id is "input_base_menu".
*
* Update the input_base, input_sequence, and output_base values which are displayed inside the STEP_3 div.
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function step_2_next() {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "step_2_next() was called at time: " + time_stamp;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
update_output_base_span_2();
hide_page_element("step_2_div");
unhide_page_element("step_3_div");
}
/**
* Regress from STEP_3 to STEP_2 of the base converter application's input form (which is substantiated using the web page file named base_converter.html).
*
* Assume that this function is called in response to the event of a button click of the BACK button displayed inside of the div whose id is "step_3_div".
*
* Reset the text displayed inside of the div element whose id is "output" to its initial state: "This sentence will be replaced with base conversion results when the CONVERT button is clicked."
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function step_3_back() {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "step_3_back() was called at time: " + time_stamp;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
initialize_output_div();
hide_page_element("step_3_div");
unhide_page_element("step_2_div");
}
/**
* Define the application interface component (to be displayed on the web page whose source code file is base_converter.html)
* which enables the user to select an INPUT_BASE.
*
* @return {String} an HTML string which is used to instantiate a DIV page element whose id is "step_0_div".
*/
function generate_html_string_for_step_0_div() {
let html_string = '<' + 'div class="module input_step" id="step_0_div"' + '>', p0 = '<' + 'p' + '>', p1 ='<' + '/' + 'p' + '>';
html_string += p0 + "STEP_0: Select an INPUT_BASE from the expandable menu. Then click the NEXT button to proceed to the INPUT_SEQUENCE step." + p1;
html_string += p0 + "INPUT_BASE := " + generate_html_string_for_base_select_menu("input_base_menu") + p1;
html_string += p0 + '<' + 'input type="button" value="NEXT" onclick="step_0_next()"' + '>';
html_string += '<' + '/' + 'div' + '>';
return html_string;
}
/**
* Define the application interface component (to be displayed on the web page whose source code file is base_converter.html)
* which enables the user to enter an INPUT_SEQUENCE.
*
* @return {String} an HTML string which is used to instantiate a DIV page element whose id is "step_1_div".
*/
function generate_html_string_for_step_1_div() {
let html_string = '<' + 'div class="module input_step" id="step_1_div"' + '>', p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>', input_sequence_span;
input_base_value = get_selected_menu_option_value("input_base_menu");
html_string += p0 + "STEP_1: Use the digit keys to enter no more than eight digits. Then click the NEXT button to proceed to the INPUT_SEQUENCE step. To re-select the INPUT_BASE, click the BACK button." + p1;
html_string += p0 + "INPUT_BASE := " + '<' + 'span style="background:#000000;color:#ffff00" id="input_base_span"' + '>' + input_base_value + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + "INPUT_SEQUENCE := " + '<' + 'span style="background:#000000;color:#ffff00" id="input_sequence_span"' + '>' + "00000000" + '<' + '/' + 'span' + '>' + p1;
html_string += '<' + 'div id="digit_buttons_div"' + '>' + generate_html_string_for_input_sequence_digit_buttons(parseInt(input_base_value)) + '<' + '/' + 'div' + '>';
html_string += p0 + '<' + 'input type="button" value="BACK" onclick="step_1_back()"' + '>';
html_string += " " + '<' + 'input type="button" value="NEXT" onclick="step_1_next()"' + '>' + p1;
html_string += '<' + '/' + 'div' + '>';
return html_string;
}
/**
* Define the application interface component (to be displayed on the web page whose source code file is base_converter.html)
* which enables the user to review input values before initiating the base conversion.
*
* @return {String} an HTML string which is used to instantiate a DIV page element whose id is "step_2_div".
*/
function generate_html_string_for_step_2_div() {
let html_string = '<' + 'div class="module input_step" id="step_2_div"' + '>', p0 = '<' + 'p' + '>', p1 ='<' + '/' + 'p' + '>';
html_string += p0 + "STEP_2: Select an OUTPUT_BASE from the expandable menu. Then click the NEXT button to proceed to the BASE_CONVERSION step. To re-enter the INPUT_SEQUENCE, click the BACK button." + p1;
html_string += p0 + "INPUT_BASE := " + '<' + 'span style="background:#000000;color:#ffff00" id="input_base_span_2"' + '>' + "???" + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + "INPUT_SEQUENCE := " + '<' + 'span style="background:#000000;color:#ffff00" id="input_sequence_span_2"' + '>' + "???" + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + "OUTPUT_BASE := " + '<' + 'span style="background:#000000;color:#ffff00" id="output_base_span"' + '>' + generate_html_string_for_base_select_menu("output_base_menu") + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + '<' + 'input type="button" value="BACK" onclick="step_2_back()"' + '>';
html_string += " " + '<' + 'input type="button" value="NEXT" onclick="step_2_next()"' + '>' + p1;
html_string += '<' + '/' + 'div' + '>';
return html_string;
}
/**
* Define the application interface component (to be displayed on the web page whose source code file is base_converter.html)
* which enables the user to click the CONVERT button.
*
* @return {String} an HTML string which is used to instantiate a DIV page element whose id is "step_3_div".
*/
function generate_html_string_for_step_3_div() {
let html_string = '<' + 'div class="module input_step" id="step_3_div"' + '>', p0 = '<' + 'p' + '>', p1 ='<' + '/' + 'p' + '>';
html_string += p0 + "STEP_3: Click the CONVERT button to convert INPUT_SEQUENCE to its OUTPUT_BASE representation. To re-select the OUTPUT_BASE, click the BACK button." + p1;
html_string += p0 + "INPUT_BASE := " + '<' + 'span style="background:#000000;color:#ffff00" id="input_base_span_3"' + '>' + "???" + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + "INPUT_SEQUENCE := " + '<' + 'span style="background:#000000;color:#ffff00" id="input_sequence_span_3"' + '>' + "???" + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + "OUTPUT_BASE := " + '<' + 'span style="background:#000000;color:#ffff00" id="output_base_span_2"' + '>' + "???" + '<' + '/' + 'span' + '>' + p1;
html_string += p0 + '<' + 'input type="button" value="BACK" onclick="step_3_back()"' + '>';
html_string += " " + '<' + 'input type="button" value="CONVERT" onclick="convert()"' + '>' + p1;
html_string += '<' + '/' + 'div' + '>';
return html_string;
}
/**
* Set the content displayed inside of the div HTML element whose id is "output" to its initial placeholder text.
*/
function initialize_output_div() {
try {
let p0 = '<' + 'p class="module output_step"' + '>', p1 = '<' + '/' + 'p' + '>';
document.getElementById("output").innerHTML = p0 + "This sentence will be replaced with base conversion results when the CONVERT button is clicked." + p1;
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of initialize_output_div(): " + exception);
}
}
/**
* Set the web page interface (i.e. base_converter.html) to its intial state.
*
* Assume that this function is called in response the event of the web page being loaed by the web browser.
*/
function initialize_application() {
try {
const time_stamp = generate_time_stamp(), p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
let message = "The web page, base_converter.html, was loaded at time: " + time_stamp;
let input_form_div = undefined;
console.log(message);
document.getElementById("time_stamped_messages").innerHTML = p0 + message + p1;
input_form_div = document.getElementById("input_form");
initialize_output_div();
input_form_div.innerHTML = generate_html_string_for_step_0_div();
input_form_div.innerHTML += generate_html_string_for_step_1_div();
input_form_div.innerHTML += generate_html_string_for_step_2_div();
input_form_div.innerHTML += generate_html_string_for_step_3_div();
hide_page_element("step_1_div");
hide_page_element("step_2_div");
hide_page_element("step_3_div");
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of initialize_application(): " + exception);
}
}
/**
* Perform the base converion using the input values which were submitted by the application user via the web page interface.
*
* Convert an INPUT_SEQUENCE (i.e. an unsigned integer consisting of no more than eight digits)
* whose base is INPUT_BASE to its equivalent representation as an unsigned integer whose base is OUTPUT_BASE.
*
* Append a time stamped message to the bottom of the web page indicating that this function was called.
*/
function convert() {
try {
const time_stamp = generate_time_stamp();
let message = "convert() was called at time: " + time_stamp;
let INPUT_BASE = 0, INPUT_SEQUENCE = "", OUTPUT_BASE = 0, OUTPUT_SEQUENCE = "";
let p00 = '<' + 'p class="module" style="border-color: #00ffff; border-width: 1px;border-style: solid;"' + '>', p0 = '<' + 'p' + '>', p1 = '<' + '/' + 'p' + '>';
console.log(message);
document.getElementById("time_stamped_messages").innerHTML += p0 + message + p1;
INPUT_BASE = parseInt(document.getElementById("input_base_span").innerHTML);
INPUT_SEQUENCE = document.getElementById("input_sequence_span").innerHTML;
OUTPUT_BASE = parseInt(document.getElementById("output_base_span_2").innerHTML);
OUTPUT_SEQUENCE = perform_base_conversion(INPUT_BASE, INPUT_SEQUENCE, OUTPUT_BASE);
document.getElementById("output").innerHTML = p00 + INPUT_SEQUENCE + " (in base-" + INPUT_BASE + ") is equal to " + OUTPUT_SEQUENCE + " (in base-" + OUTPUT_BASE + ")." + p1
}
catch(exception) {
console.log("An exception to normal functioning occurred during the runtime of convert(): " + exception);
}
}