Hong-Phuc Bui
2025-01-16 2889de7f0c2d587a17fbd322af57c29e84238620
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
/**
 * hash-and-star.js
 *
 */
 
import {terminal} from "./dfhi.js";
 
window.main = function(...argv) {
    let n = Number.parseInt(argv[0]);
    let stars = '<table>';
    // Code to create table (with tr and td....
    let space = '<td> </td>';
    let star = '<td>*</td>';
    // a table with n lines
    for(let line = 0; line < n; ++line) {
        stars += '<tr>';
        // each line has n/2 stars and n/spaces
        for(let col = 0; col < n; ++ col){
            if (col % 2 == 0) {
                stars += star;
            }else {
                stars += space;
            }
        }
        stars += '</tr>';
    }
    stars += '</table>';
    terminal.printh(stars);
};