What steps should be taken to modify it so that the user is prompted to input the time in minutes

I attempted to modify the user input in minutes by changing "remseconds" to remminutes and adjusting the calculations to "x 60", but unfortunately, nothing happened as expected.

Instead of "remseconds," I tried using remminutes and multiplied it by 60, but no changes occurred.

const container = document.querySelector('.counter');
const buttonsDiv = document.querySelector('.buttons');
const secInput = document.getElementById('seconds');

var seconds;
var remseconds;
var minutes;
var toCount = false;

function toSubmit() {
  display('start');
  remove('seconds');
  remove('ok');
  seconds = Number(secInput.value);
  counting();
}

function display(e) {
  document.getElementById(e).style.display = 'block';
}

function remove(e) {
  document.getElementById(e).style.display = 'none';
}

function check(stat) {
  if (stat.id == "start") {
    display("stop");
    remove("start");
    toCount = true;
  } else if (stat.id == "stop") {
    display("continue");
    remove("stop");
    toCount = false
  } else {
    display("stop");
    remove("continue");
    toCount = true;
  }
}

function count() {
  if (seconds > 0) {
    if (toCount == true) {
      seconds--;
      remseconds = seconds % 60;
      minutes = Math.floor(seconds / 60);

      if (minutes < 10) {
        minutes = "0" + minutes;
      }

      if (remseconds < 10) {
        remseconds = "0" + remseconds;
      }

      container.innerHTML = minutes + " : " + remseconds;
    }
  } else {
    container.innerHTML = "DONE!";
    buttonsDiv.style.opacity = "0";
  }
}

function counting() {
  remseconds = seconds % 60;
  minutes = Math.floor(seconds / 60);


  if (remseconds < 10) {
    remseconds = "0" + remseconds;
  }

  container.innerHTML = minutes + " : " + remseconds;
  setInterval(count, 1000);
}
<!DOCTYPE html>
<html class="class2">

<head>
  <title>CountDown</title>
  <link rel="stylesheet" type="text/css" href="style.css">
  <link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
</head>

<body>
  <header>
    <h1>CountDown</h1>
  </header>
  <div class="content">
    <div class="counter"></div>
    <input type="number" id="seconds" placeholder="Seconds">
    <div class="buttons">
      <button class="btn start" id="start" value="1" onclick="check(this)">Start</button>
      <button class="btn start" id="continue" value="1" onclick="check(this)">Continue</button>
      <button class="btn stop" id="stop" value="0" onclick="check(this)">Stop</button>
      <button class="btn start" id="ok" onclick="toSubmit()">Submit</button>
    </div>
  </div>
  <script type="text/javascript" src="main.js"></script>

</body>

</html>

If you have any suggestions or solutions, please feel free to share them.

Answer №1

I spent a good amount of time editing the answer over at js seconds countdown

The key is to obtain minutes and then convert them to seconds by multiplying by 60 in the counting() function.

const container = document.querySelector('.counter');
const buttonsDiv = document.querySelector('.buttons');
const minInput = document.getElementById('minutes');

var seconds;
var remseconds;
var minuts;
var toCount = false;

function toSubmit() {
  display('start');
  remove('minutes');
  remove('ok');
  minuts= Number(minInput.value);
  counting();
}

function display(e) {
  document.getElementById(e).style.display = 'block';
}

function remove(e) {
  document.getElementById(e).style.display = 'none';
}

function check(stat) {
  if (stat.id == "start") {
    display("stop");
    remove("start");
    toCount = true;
  } else if (stat.id == "stop") {
    display("continue");
    remove("stop");
    toCount = false
  } else {
    display("stop");
    remove("continue");
    toCount = true;
  }
}

function count() {
  if (seconds > 0) {
    if (toCount == true) {
      seconds--;
      remseconds = seconds % 60;
      minuts = Math.floor(seconds / 60);

      if (minuts < 10) {
        minuts = "0" + minuts;
      }

      if (remseconds < 10) {
        remseconds = "0" + remseconds;
      }

      container.innerHTML = minuts + " : " + remseconds;
    }
  } else {
    container.innerHTML = "DONE!";
    buttonsDiv.style.opacity = "0";
  }
}

function counting() {
  seconds = minuts*60;
  remseconds = seconds % 60;
  //minuts = Math.floor(seconds / 60);


  if (remseconds < 10) {
    remseconds = "0" + remseconds;
  }

  container.innerHTML = minuts + " : " + remseconds;
  setInterval(count, 1000);
}
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

html, body{
    height: 100%;
}
body{
    width: 100%;
    height: 100%;
    background: linear-gradient(to left top, #0045D6, #00A9f6);
}

header{
    width: 100%;
    height: 13vh;
    background-color: #fff;
    color: #0045F6;
    display: flex;
    justify-content: center;
    align-items: center;
}

.content{
    width: 100%;
    height: 60vh;
    font-size: 3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.content #minutes{
    width: 250px;
    font-size: 2rem;
    padding: 1rem;
    outline: none;
    background: none;
    border: none;
    border-bottom: 3px solid #fff;
    color: #fff;
}

#minutes::placeholder{
    color: #ddd;
    font-size: 1.7rem;
}

.btn{
    background-color: #fff;
    border-radius: 4px;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 0.8rem 1.7rem;
    font-size: 1.2rem;
    font-weight: 700;
}

.start{
    color: #1f0;
}

.stop{
    color: #E00;
}

#start, #stop, #continue{
    display: none;
}

.counter{
    color: #fff;
}
 <!DOCTYPE html>
<html class="class2">
<head>
    <title>CountDown</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
</head>
<body>
    <header>
        <h1>CountDown</h1>
    </header>
    <div class="content">
        <div class="counter"></div>
        <input type="number" id="minutes" placeholder="Minutes">
        <div class="buttons">
            <button class="btn start" id="start" value="1" onclick="check(this)">Start</button>
            <button class="btn start" id="continue" value="1" onclick="check(this)">Continue</button>
            <button class="btn stop" id="stop" value="0" onclick="check(this)">Stop</button>
            <button class="btn start" id="ok" onclick="toSubmit()">Submit</button>
        </div>
    </div>
    <script type="text/javascript" src="main.js"></script>

</body>
</html>

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

Is there a way to change the label of a link in JointJS by clicking on it?

Lately, I've been facing a bit of a challenge that I can't seem to figure out. Here's the situation: What I'm aiming for is to be able to click on a link in my graph and change the label associated with it. Currently, the workaround I& ...

The failure of the Selenium script can be attributed to the presence of the AJAX

Struggling to automate an application with an AJAX loader causing issues? Getting the dreaded error message about element not being clickable when the loader is active? Frustrating, right? But fear not! I have devised a clever solution in the form of a wr ...

Looking to update a form when clicking on the change button?

Two JSON files, "a.json" and "b.json", are in question. A different form needs to be displayed when the user clicks on each respective button. The issue arises when clicking on the second button does not show the second form as intended. The goal is to onl ...

Simple JavaScript numeric input field

Hey there, I'm a beginner learning JavaScript. I'm currently working on creating a program that adds numbers input through text fields. If you want to check out the HTML code, visit this link on JS Fiddle: http://jsfiddle.net/fCXMt/ My questio ...

How can I create a Bootstrap button with a custom href link in my code

I have created a button, is it possible to add an "href" link to this code? My link isn't working! <button class="buttoncostum"> <a href="http://example.com/"><span class="glyphicon glyphicon-th-list" style="color:white" aria-hidden=" ...

What's causing this bootstrap button to act up?

https://i.sstatic.net/9ZAz9.png It was expected that the button would appear on the right side while the navigation titles would be displayed on the left. <nav id="mainNavbar" class="navbar navbar-dark bg-dark navbar-expand-md"> ...

Using the HTML5 Video Element on an iPad

Having trouble playing a Quicktime movie (.mov) on my iPad. Instead of the video, I just see a black area. Not sure if using the VIDEO tag will work for Quicktime videos. Does the VIDEO tag even support the .mov format? What's the best way to play a ...

Is there a way to prevent the text box from expanding beyond the small breakpoint?

Help! I'm trying to control the size of a Bootstrap 4 input text box. I need it to stop growing after the small breakpoint, so it doesn't expand to the full width of the screen. ...

Is it possible to dynamically change the color of text based on its position using CSS, JS, or JQuery?

I am currently working on a corporate website and have been tasked with creating a unique design for a specific page. The design includes the following elements: A body background gradient that transitions from their primary color to white in a top-to-bot ...

What is the best way to set the input type in AngularJS based on a variable?

Is there a way to dynamically set the input type based on another variable in AngularJS? I was considering using a directive that triggers from an onclick event to change the input type, but I'm not entirely sure. FIRST //loop <a class="orgTitle" ...

Creating Swagger clients from scratch

I am working on a project that is based on npm and I am looking to add a swagger-based REST API client. My plan is to use a yaml file for the API description and generate the client during the build process. Are there any popular methods or tools for acc ...

use element ui tree and vue to filter files according to selected folder

Utilizing the element UI treeview to showcase folders. Each folder or its child folder contains files that need to be displayed based on folder selection. While it's easy to filter and list out these files in a normal list, I am facing challenges with ...

Challenges with form validation

Hello everyone, I'm a newbie to JS and struggling with my code. It seems like everything should work, but it just won't. The issue seems to be with the phone number form validation. I've written code that, in theory, should do the job, but ...

Setting the y-axis range in d3.js and nvd3.js: A complete guide

I'm attempting to define the y-axis range of the chart to be between 1 and 100. After reviewing the API documentation, I came across a potential solution involving axis.tickValues which can be found here: https://github.com/mbostock/d3/wiki/SVG-Axes# ...

What is the best way to display the press down (:active) effect before releasing the finger?

Is there a way to display the :active CSS effect on mobile devices while the user's finger is still touching the screen? I have noticed that the effect only shows after the finger is lifted, but I prefer the way Amazon's buttons display this effe ...

Paragraph Separated by Bullets Without Bullets At End of Line

I need assistance in creating a unique type of list that I call a "bullet separated paragraph list" by using a javascript array of strings. For example: item • item • item • item • item     item • item • item • item item • ...

Exploring Bootstrap 5: Utilizing flex columns for children elements with full width and equal height display

https://i.sstatic.net/hpajE.png Is there a way to have elements on the left stack vertically, with equal height and width of the parent element, filling the entire height? I need this layout for three or more elements using Bootstrap 5. This is the HTML ...

Develop a customizable contact chatlist feature with sorting and paging capabilities by integrating mongodb

I'm currently working on developing a chat application using nodejs and mongodb. One of the key features I need to implement is a dynamic contact list that orders contacts based on the latest messages sent and enables paging with 15 items per page. I& ...

The Bootstrap tooltip fails to display the visual style of the tooltip, only showing the data

Following the Bootstrap documentation for tooltips, I have tried to make the tooltip function work properly. However, when I hover over the text, the tooltip text Some tooltip text! only shows up with the alt="" function, but not styled as described in the ...

What is the reason for $addToSet always returning 1 upon update?

Recently, I have been utilizing mongoose for my project. I encountered an issue when attempting to update my data in a specific way. model.update({_id: id}, {$addToSet: {refs: refId}}, function(err, numAffected){ console.log(numAffected); }) Although t ...