Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8328225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:22:05+00:00 2026-06-09T01:22:05+00:00

So I have two scripts on a page: The first one randomly chooses a

  • 0

So I have two scripts on a page:

  • The first one randomly chooses a number from an array and inserts it into an element called ‘number’.
  • The second one is a countdown script which counts down from two variables which are interpreted as minutes and seconds. It then plays a sound once the countdown has reached zero.

At the moment, the second script is all manually set-up, so the number of minutes and seconds are hard-coded into the script itself. I’d like the second script to take whatever number was inserted into the page by the first script, and use it as its variable.

Here’s a better example of how I’d like it to work:

You load the page, and it tells you that you only have (X) minutes to spare (X = inserted by first script), and whatever (X) is, acts as the ‘minutes’ variable in the second script, which is now displaying a countdown from (X) minutes elsewhere on the page.

The first script’s output is inserted into:

<span id="minutes"></span>

And here’s the code for the second script (the one that needs changing):

var interval;
var minutes = 5;
var seconds = 0;
window.onload = function() {
    countdown('countdown');
}

    function play(file) {
var embed = document.createElement("embed");

embed.setAttribute('src', file);
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);

document.body.appendChild(embed);
}

function countdown(element) {
    interval = setInterval(function() {
        var el = document.getElementById(element);
        if(seconds == 0) {
            if(minutes == 0) {
                el.innerHTML = "Time's up!";                    
                clearInterval(interval);
    play('alarm.mp3');
                return;
            } else {
                minutes--;
                seconds = 60;
            }
        }
        if(minutes > 0) {
            var minute_text = minutes + (minutes > 1 ? ' minutes' : ' minute');
        } else {
            var minute_text = '';
        }
        var second_text = seconds > 1 ? 'seconds' : 'second';
        el.innerHTML = minute_text + ' ' + seconds + ' ' + second_text + ' remaining';
        seconds--;
    }, 1000);
}

I’ve tried changing

var minutes = 5;
var seconds = 0;

to

var minutes = document.getElementById(minutes);
var seconds = 0;

(the second script runs after the first one)

… but it doesn’t seem to work, just starting at ‘null’ minutes.

Could anyone shed any light on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:22:07+00:00Added an answer on June 9, 2026 at 1:22 am

    Solution:

    var minutes = Number(document.getElementById('minutes').innerHTML);
    

    Explanation:

    You probably mean the string minutes: (add quotes)

    var minutes = document.getElementById('minutes');
    var seconds = 0;
    

    But that returns the DOM object. The innerHTML will return what is inside the <span> tag

    var minutes = document.getElementById('minutes').innerHTML;
    

    But then you need to realise that it is a string everywhere it is used, so that where you might have had implicit type conversions with string + number you will now have to do it explicitly, or change code to allow for implicit conversion, or handle it when you first instantiate minutes.

    Thus we do the type conversion using Number()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two scripts that are called in one program, the first script creates
I have two aspx page on my application. From the first one, lets say
I have two scripts running on the same page, one is the jQuery.hSlides.js script
I have a two forms on a page. The first one has several quantity
I have a php page that creates page data from two .txt files (one
I have two slideshows in one page using javascript http://www.flickrshow.com/static/scripts/flickrshow-7.2.min.js , but it only
I have two scripts on the same page, both running sliders, and the first
Default3.aspx This is my first page. in which i have two textbox and one
I have written two scripts where one script calls subprocess.Popen to run a terminal
I have two Javascript scripts on a site. One is an accordion (show/hide) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.