Ways to integrate data produced from two distinct functions into a third function

I have two data sets that were generated by separate functions and are of different types. These datasets cannot be combined (concatenated, joined, etc.). I want to use both datasets in a third function as shown below. How can I achieve this?

function a() {
    var x = Math.ceil((Math.random()*100)+1)
    c(x);
}
function b() {
    var y = Math.floor((Math.random()*100)+1)
    c(y);
}
function c(x,y) {
    console.log(x + ' : ' + y);
}

a();
b();

Answer №1

    function generateRandomCeil() {
        var number = Math.ceil((Math.random()*100)+1)
        return number;
    }
    function generateRandomFloor() {
        var number = Math.floor((Math.random()*100)+1)
        return number;
    }
    function displayNumbers(x, y) {
        console.log(x + ' : ' + y);
    }

displayNumbers(generateRandomCeil(), generateRandomFloor());

Answer №2

    let aFunction = () => {
        let numX = Math.ceil((Math.random()*100)+1)
        return numX;
    }
    
    let bFunction = () => {
        let numY = Math.floor((Math.random()*100)+1)
        return numY;
    }
    
    let cFunction = (numX, numY) => {
        console.log(numX + ' : ' + numY);
    }

    cFunction(aFunction(),bFunction());

This script utilizes functions to generate random numbers and pass them as arguments to another function for output. This improves readability and simplifies debugging overall!

Answer №3

Is it possible to showcase variations x and y publicly?

var x;
var y;
function a() {
    x = Math.round((Math.random()*100)+1)
    showValues(x,y);
}
function b() {
    y = Math.floor((Math.random()*100)+1)
    showValues(x,y);
}
function showValues(x,y) {
    console.log(x + ' : ' + y);
}

a();
b();

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

Iterating through an array in Javascript to create a new array filled with objects

Is there a way to iterate through an array of strings and convert them into an array of objects based on their values? For instance, if the array looks like this: [a,a,a,b,b,c,d] I aim to cycle through the array and create objects with key-value pairs t ...

Discovering the identification of a comment in JavaScript

Here is the code snippet I am working with: <a onclick="lel($(this),'212345555')" class="button"> <a onclick="lel($(this),'241214370')" class="button"> <a onclick="lel($(this),'248916550')" class="button"> & ...

A guide to reordering table rows by drag-and-drop with JavaScript

Seeking assistance with swapping table rows using JQuery UI. Although successful in the swap, struggling to retrieve row numbers during the drag and drop event. Understanding the row number is essential for subsequent tasks. Any help would be greatly appre ...

What could be the reason that angularjs html template requests aren't appearing in the top websites when viewed in a

After referring to the link , I discovered a way to determine which programming tools different sites use for application development. However, when I debug HTTP requests using Firebug, I noticed that HTML requests are not explicitly shown in the log. Alt ...

Functional React component using a stateless class within

I need some valuable suggestions for a specific scenario. I am interested in developing my own Datetimepicker react component. I have been exploring different codes to easily create a calendar and came across a Regular Class that generates the calendar. M ...

Unable to retrieve a response, the operation `users.findOne()` has exceeded the buffering time limit of 10000ms

I encountered an issue when attempting to make a POST login request. The frontend is deployed on Netlify here, and the backend is deployed on Heroku here. Here are my backend logs . I am receiving `users.findOne()` buffering timed out after 10000ms in ...

Using a combination of stringify, regular expressions, and parsing to manipulate objects

As I review code for a significant pull request from a new developer, I notice their unconventional approach to editing javascript objects. They utilize JSON.stringify(), followed by string.replace() on the resulting string to make updates to both keys a ...

The status of the WebRTC connection has changed to "disconnected" due

My attempt at setting up a basic video chat using webRTC has hit a roadblock. While everything functions smoothly on a local network, trying to establish an Internet connection results in termination of the connection. I've implemented iceServers: [{ ...

A helpful guide on rendering nested maps from JSON data in React.JS

I am attempting to display menu values from a JSON data. This menu has multiple levels, so I am using a nested map function to render the complete menu. const menu = { data:[ { title: "Home", child: [ { title: "SubL ...

"What is the best way to access the value of a useState variable in ReactJS on a global

Below is my reactJS code snippet - useEffect(()=>{ const getinterviewerDetails= async ()=>{ const data1 = await axios.get("http://localhost:8083/api/GetProduct") .then(response => { console.log("role is " ...

What is the best way to establish communication between a server and client using sockets in Node.js?

Presently, I am in the process of developing a JavaScript application using AppJS. I'm encountering some difficulties understanding the communication between the client and server. Issue with Menu Bar and Socket Interaction The main challenge lies ...

Encountering an issue while attempting to send a POST response through Node Express, specifically an error related

Encountering an error after completing registration, specifically when attempting to respond to the POST request. (user is added to database successfully) express deprecated res.send(status, body): Use res.status(status).send(body) instead auth\regi ...

Tips for verifying the compatibility of elements as parent or child components

Is it possible in JavaScript to verify if an HTML element can be a child of another element? For instance: Can an unordered list (<ul>) contain a list item (<li>) as a valid child element? - Yes Can an unordered list (<ul>) contain ano ...

How can I invoke a jQuery widget's public method from the outside using the plugin reference?

I have encountered an issue with a plug-in popup that I created. I am attempting to reference and access the public method of the plug-in, but I am receiving an 'Undefined Function' error. var pop = $('.divCls').popup(); pop.setTit ...

Updates to AngularJs models are not being reflected

I am facing an issue with my model that I want to make editable, but for some reason nothing changes - the textbox fails to appear and the model remains unchanged when using ng-view. I can confirm that the function enableEditor() is being triggered as I s ...

Steps for integrating a valid SSL certificate into a Reactjs application

After completing my ReactJS app for my website, I am now ready to launch it in production mode. The only hurdle I face is getting it to work under https mode. This app was developed using create-react-app in a local environment and has since been deployed ...

Managing a collection of user inputs in React

I am working on a table where I have to create a list of input elements. These input elements will come with a default value which can be changed by the user from the maximum number (default value) down to 0, or they can send this maxNumber. There is also ...

Validation of HTML5 forms using jQuery

I am in need of a jQuery-based validation library that will kick in when the browser does not support HTML5 for specific attributes like 'required' or 'placeholder'. After looking around, I have come across several libraries but they ar ...

Creating a writer for nested JSON arrays in ExtJS 4

I'm currently tackling the challenge of working with JSON data that has a nested structure in ExtJS4. I kindly request not to provide responses similar to what can be found here as it is not the correct solution for me. My approach involves using expa ...

Exploring an unusual HTML structure using Python's Beautiful Soup and urllib for web scraping

While extracting data may not be a challenge, the real issue lies in locating it. My focus is on scraping football data from a website that presents statistics either for all years or for specific seasons. However, despite selecting a particular season, ...