Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Initialize the hourglass parameters const N = 2 8 ; / / Size of the clock ( adjust as needed ) let upperChamber
Initialize the hourglass parameters
const N ; Size of the clock adjust as needed
let upperChamber ;
let lowerChamber ;
Get user inputs for outer border and inner material
const outerBorder window.promptEnter the character for the outer border: ;
const innerMaterial window.promptEnter the character for the inner material: ;
Construct the initial hourglass
for let i ; i N; i
let row ; Initialize an empty string for each row
for let j ; j i; j
row ; Add spaces to the left of the pattern
for let j ; j N i; j
if j j N i
row outerBorder; Use # for the outer border
else
row innerMaterial; Add dots inside the pattern
console.logrow; Print the row
Construct the lower half of the hourglass
for let i N; i ; i
let row ;
for let j ; j i; j
row ;
for let j ; j N i; j
if j j N i
row outerBorder; Use # for the outer border
else
row ; Add spaces between outer materials
console.logrow;
console.log;
let currentTime ;
Main loop to accept user commands
while true
const command window.promptEnter a command next prev, nexus, quit:;
if command "next"
Update the clock for the next hour
const innerRows currentTime ; because we reset at hours
Construct the updated upper chamber string
let updatedUpperChamber ;
for let i ; i N; i
let row ; Initialize an empty string for each row
for let j ; j i; j
row ; Add spaces to the left of the pattern
for let j ; j N i; j
if j j N i
row outerBorder; Use # for the outer border
else
if row currentTime
row ;
else
row innerMaterial; Add dots inside the pattern
console.logrow; Print the row
Construct the lower half of the hourglass
for let i N; i ; i
let row ;
for let j ; j i; j
row ;
for let j ; j N i; j
if j j N i
row outerBorder; Use # for the outer border
else
row ; Add spaces between outer materials
console.logrow;
Update the current time
currentTime currentTime ; Increment and reset at hours
Display the updated clock
console.logHourglass at t$currentTime:;
console.logupdatedUpperChamber;
else if command "prev"
if true hourglasspattern reverses and it does the opposite and fills the top of the hourglass.
else if command "nexus"
if true hourglasspattern reverses to innitial pattern.
else if command "quit"
console.logExiting the hourglass simulation. Goodbye!";
break;
else
console.logInvalid command. Please enter
# # # # # # # # # # # # # # # next, prev, nexus, or quit.";
fix the code so it is functional please.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started