Loop stops after completing one iteration

I am currently working on a program that automatically generates ASCII text based on input numbers. Essentially, when a number is provided as input to the function, it will be displayed as magnified ASCII text. For example, an input of 0123456789 would generate the following:

-**----*--***--***---*---****--**--****--**---**--
*--*--**-----*----*-*--*-*----*-------*-*--*-*--*-
*--*---*---**---**--****-***--***----*---**---***-
*--*---*--*-------*----*----*-*--*--*---*--*----*-
-**---***-****-***-----*-***---**---*----**---**--
--------------------------------------------------

I have organized each number into an array and my code loops through this array for each number entered, eventually building the final combined image. The generation process appears to be functioning correctly, but I am encountering an issue where the end variable is not being properly accessed at the conclusion. The main loop only processes the initial number from the input before stopping. Any assistance with resolving this problem would be greatly appreciated! http://jsfiddle.net/dmcuj2z5/

function printNums(line){
    var nums = [['12','03','03','03','12'],['2','12','2','2','123'],['012','3','12','0','0123'],['012','3','12','3','012'],['1','03','0123','3','3'],['0123','0','012','3','012'],['12','0','012','03','12'],['0123','3','2','1','1'],['12','03','12','03','12'],['12','03','123','3','12']];

    var answer = ['','','','','',''];
    var allowed = '0123456789';
    for(var i=0;i<line.length;i++){
        var num = line[i];
        if(allowed.indexOf(num) !== -1){
            for(var l=0;l<6;l++){    
                var print = '';
                for(var c=0;c<5;c++){
                    if(nums[num][l].indexOf(c) !== -1){
                        print += '*';
                    }else{
                        print += '-';
                    }
                }
               answer[l] += print;
            }
        }
    }
    alert(answer);
}

printNums('123');

Answer â„–1

Would you like help with a coding challenge involving arrays and outputting values?

function printNums(line){
    var nums = [['12','03','03','03','12'],['2','12','2','2','123'],['012','3','12','0','0123'],['012','3','12','3','012'],['1','03','0123','3','3'],['0123','0','012','3','012'],['12','0','012','03','12'],['0123','3','2','1','1'],['12','03','12','03','12'],['12','03','123','3','12']];

    var answer = ['','','','','',''];
    var allowed = '0123456789';
    for(var i=0;i<line.length;i++){
        var num = line[i];
        if(allowed.indexOf(num) !== -1){
            for(var l=0;l<5;l++){    
                var print = '';
                for(var c=0;c<5;c++){
                    if(nums[num][l].indexOf(c) !== -1){
                        print += '*';
                    }else{
                        print += '-';
                    }
                }
               answer[l] += print;
            }
        }
    }
    console.log(answer.join("\n"));
}

printNums('123');

// --*--***--***--
// -**-----*----*-
// --*---**---**--
// --*--*-------*-
// -***-****-***--

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering issues with AngularJS number filter when integrating it with UI grid

When using the angularjs number filter in angular-ui-grid, I am facing an issue. The filter works perfectly fine within the grid, but when I export the grid to csv and open it in Excel, the formatting is not maintained. I have included the filter in the e ...

Adding images to HTML using JavaScript below existing images

I'm currently working on a JavaScript game and I want to implement a feature where my character can move under blocks (isometric PNG images) instead of just sliding through them. Is there a way to dynamically adjust my character's position in the ...

The debate between classes and data attributes in terms of auto field initialization

A Brief Background In the realm of javascript/jQuery, I've crafted a method that traverses through various fields and configures them based on their type - be it dropdowns, autocomplete, or text fields... The motivation behind this is my personalize ...

Having trouble with making a POST request in Node.js using Express.js and Body-parser?

Just starting out with nodejs and currently in the learning phase. I've encountered an issue where my POST request is not functioning as expected. I set up a basic html form to practice using both GET and POST requests. Surprisingly, the GET request w ...

Is it beneficial to create two distinct node applications—one to serve a webservice and another to consume that webservice in order to display it on a browser?

Is it more efficient to run two separate node instances for different purposes (webservice engine/data engine and webservice consumer), or is it better to combine both functions in the same application? ...

At which location within the script should I insert the document.title in order to update the title every xx milliseconds?

I have been working on a script that refreshes certain #id's. Additionally, I would like to update the page title, which involves some flask/jinja2. I've attempted placing document.title = {% block title %} ({{online_num}}) Online Players {% en ...

What steps do I need to take in order to establish a connection to a GridFS bucket

I have successfully implemented file uploads using a gridfs bucket. However, I am facing challenges with downloading files. For retrieving files, I need to access the bucket instance that I created within the database connection function: const connectDB ...

Attention: The PageContainer component requires React component classes to extend React.Component

I recently started using react-page-transitions in my project and encountered the following warning message: "PageContainer(...): React component classes must extend React.Component." Here is a snippet of my code: import React from 'react'; ...

Encountered a Socket.io issue: CONNECTION_TIMED_OUT_ERROR

I'm in the process of developing a simple HTML chat program. I've set up a node server for testing, but encountering a socket error when trying to access the HTML page. This is my first experience with Node.js and setting up a server, so it' ...

'The error thrown states: "ReferenceError: httpResponse is not defined" occurs while attempting to parse the JSON response from a Parse HTTP

My commitment statement involves sending multiple requests to eBay, each time using the properties of a matchCenterItem as parameters. Once all instances have been processed, I aim to transmit all the responses to my iOS application. However, my effort to ...

What steps should I take to host my Vue js single page application on my Django server?

At present, I am in the process of following a tutorial to integrate my Vue.js frontend with my Django backend. You can find the guide here: https://medium.com/@williamgnlee/simple-integrated-django-vue-js-web-application-configured-for-heroku-deployment-c ...

What is the reason behind having to restart the npm server each time?

When first learning Reactjs with VSCode, there was no need to restart the server after making modifications. However, now I find that I must restart the server every time I make a change in order for those changes to be applied. ...

SignalR enables the display of identical dashboard data pulled from queries on various browsers. By utilizing SignalR/hub, MVC, and C#.NET, the data can

Encountering an issue with my signalr/hub while fetching dashboard data. I'm using 2 browsers to access data based on dates. However, when searching for July on browser 1 and then switching to another month on browser 2, the data in browser 1 gets upd ...

What happens to the content within a <textarea> element if it is not enclosed between the opening and closing tags?

Here's a puzzling situation - I've entered the word Hello. into a <textarea>, and while I can see it on my screen, it doesn't show up between the opening and closing <textarea> tags. It may seem like a simple issue, but I'v ...

What could be causing this issue to not function properly in JavaScript?

Here is a JavaScript code snippet that I am working on: var inx=[2,3,4,5]; var valarray=[]; for (i=0; i<inx.length; i++) { valarray[i]==inx[i]; } for (i=0; i<inx.length; i++) { var posi=inx.indexOf(3); var valy=valarray[posi-1]+1; v ...

Repairing div after upward scrolling and maintaining its fixation after refreshing the page

I have encountered two issues with this particular example: One problem is that the fixed_header_bottom should stay fixed beneath the fixed_header_top when scrolling up, causing the fixed_header_middle to gradually disappear as you scroll up, or vice v ...

The function for the Protractor promise is not defined

UPDATE: After some troubleshooting, I believe I have identified the issue causing it not to work. It seems that I am unable to pass arguments along when calling flow.execute(getSpendermeldung). Does anyone have a better solution than wrapping the ApiCall i ...

Loop through the input fields using ng-repeat while maintaining consistent values for each iteration

I am facing an issue with my ng-repeat loop where I have a comment input inside it. The problem is that when I start typing in the first input, the text appears simultaneously in all other inputs as well. I have tried adding a unique ID but it didn't ...

Can a shape similar to an inverted circle be created using CSS and jQuery?

I'm stumped on how to create an inverted circle in the corners. I've included a picture for reference. https://i.stack.imgur.com/jeNdh.jpg Is it feasible to achieve this effect using CSS3 or maybe jQuery? ...

Tips for transmitting an array of Objects to AngularJS

Summary I'm curious about how I can successfully send the following array of objects from NodeJS to an AngularJS app. var players = [ Footer: { username: 'Footer', hp: 200, exp: 1 }, Barter: { username: 'Barter', hp: 200, e ...