Can someone please provide assistance with a JavaScript game?

Is there a way to prevent the game from allowing unlimited money to be generated by simply pressing a button?

var workbard = document.getElementById("workbar");
function work() {
  var zaman = setInterval(function () {
    workbard.value +=1;
    if (workbard.value == 10) {
      workbard.value -=11;
      workbard.style.visibility = 'hidden'
      clearInterval(zaman);
      money = money +=5;
      experience = experience +=10;
      document.getElementById("para").innerHTML= ":" +money;
      document.getElementById("exp").innerHTML=":" +experience;
    }
<progress id="workbar" alue="0" max="10"></progress>
<button type ="button"id="workb2"onclick="work(),document.getElementById('workbar').style.visibility='visible'">Work</button>

Answer №1

To get started, make sure to set up your variables and establish a limit. Then, incorporate an if statement for proper execution.

var workbar = document.getElementById("workbar");
var money = 0;
var experience = 0;
var limit = 30;

function work() {
  var timer = setInterval(function () {
    workbar.value += 1;
    
    if (workbar.value == 10) {
      workbar.value -= 11;
      workbar.style.visibility = 'hidden';
      clearInterval(timer);
      money += 5;

      if (money > limit) {
        money = limit;
      }
      
      experience += 10;
      
      document.getElementById("para").innerHTML = ":" + money;
      document.getElementById("exp").innerHTML = ":" + experience;
    }
  });
}
<progress id="workbar" value="0" max="10"></progress>
<button type="button" id="workb2" onclick="work(),document.getElementById('workbar').style.visibility='visible'">Work</button>

<div id='para'></div>
<div id='exp'></div>

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

The post request is successful in Postman and cURL, however, it faces issues when executed in Angular

A remote server and a local client are set up to communicate through a simple post request. The client sends the request with one header Content-Type: application/json and includes the body '{"text": "hello"}'. Below is the s ...

Is it possible for me to retrieve/load a <datalist> element from a different file?

I'm in the process of developing a Google Chrome extension that essentially consists of a dropdown menu and an input box with datalists. The user can change their selection in the dropdown menu, which will then switch the datalist being used by the in ...

Transformation of intricate object

I am currently in search of a reliable utility (such as Lodash) that can assist me in transforming deeply nested objects like the example shown below: Source Data: [{ "category": "blogs", "results": { "__type": "SearchProvider.SearchResultCon ...

Passing parameters with AngularJS can return as Resteasy @FormParam being null

Struggling to integrate AngularJS on the front end with Resteasy as my Rest API. The issue I'm encountering is that my @FormParam values are always null when sending parameters using AngularJS. Below is a snippet of my JavaScript code: $scope.addPe ...

Pass a variable value as a parameter to a jQuery function using code-behind

Within my code behind, I am retrieving the [IDphoto] from an SQL database. My goal now is to pass this IDphoto as a parameter to a jQuery function upon onClick. How can I achieve this? Code behind sb.AppendFormat("<a onclick='popup()' href=& ...

Is it possible to utilize a tracking pixel (invisible GIF) as a background image within a stylesheet?

I'm curious to know if adding a tracking pixel (a transparent GIF with server logging) as a background-image in a linked stylesheet will have the same impact as if it were a regular <img> on a webpage. After conducting a quick test using Chrome ...

Unexpected behavior when changing height of a md-button

Struggling to adjust the height of an md-button has been quite frustrating for me. It's been hard-coded to be 25px high within the <button-container> element, but the hover animation still overflows this set height, as shown here: https://i.ssta ...

Is it possible for me to customize the default angular filter in order to prioritize displaying strings that begin with the search term?

In my current project, we are dealing with a massive list of strings (17,000+ at times) and have implemented an input box for filtering the list. Initially, I used Angular's default filter, but then a request came in to sort the list so that strings s ...

Does Internet Explorer 10 support the FormData object?

I've developed a JavaScript app that enables me to upload images asynchronously, and it works seamlessly in most browsers. However, the infamous Internet Explorer is causing some trouble... To address this issue, I devised a workaround for IE9- versi ...

Operating on an angular table arr with the splicing of an object attribute

Encountering an issue. I have a component with some logic for creating and deleting input fields .ts export class AppComponent implements OnInit { resource: Resource[] = []; fieldId = 0; testArr = ['1', '2', '3', ' ...

Utilize the jQuery .Ajax() function to selectively extract and save data into a variable

Hello, I am new to jQuery and currently facing an issue that I need help with. My project consists of two pages - 1.JSP and 2.html. The task at hand is to extract selected data from 2.html and utilize it on 1.JSP. While using the .load function solved thi ...

Emailer: Missing Salutation

While attempting to send emails using Node with Nodemailer (https://github.com/nodemailer/nodemailer), the sendMail call from the Nodemailer transporter is throwing an error message of Greeting never received when connected to an Ethereal test email accoun ...

Automatically execute a function every 5 seconds in Angular application

I have a component in Angular that is responsible for fetching data from the backend. Below is the code snippet of the component export class MessagesComponent implements OnInit { constructor(private _router: Router, private http: HttpClient) { } t ...

How to keep text always locked to the front layer in fabric.js without constantly bringing it to the front

Is it possible to achieve this functionality without using the following methods? canvas.sendBackwards(myObject) canvas.sendToBack(myObject) I am looking to upload multiple images while allowing them to be arranged forward and backward relative to each o ...

Determine the height of an element using Vue.js

Is there a way to accurately determine the height of one div in order to match it with another? Using clientHeight doesn't seem to provide the correct value, possibly due to elements not being fully loaded. I have tried using window.load() to delay un ...

What is the best way to dynamically load utility methods in a Next.js application?

Do you believe it is beneficial to organize logic into utility files and dynamically load them to enhance the speed of a website? For example, I have a method called getInvoiceDetails in a file named getInvoiceDetails.tsx: export default const getInvoiceD ...

Having trouble incorporating a class with if and else statements, the code isn't functioning as expected

I am attempting to apply a class with an if-else statement, but for some reason it is not progressing past the if condition and reaching the else block. $('.headings aside').click(function() { if ($(this).children('span').hasClass( ...

Guide on effectively incorporating CSS and JS files packaged as an NPM module using gulp

How can I efficiently incorporate CSS and JS files from an NPM package, installed via gulp, into my index.html file? I have used NPM to install the Materialize CSS framework by running: npm install --save-dev materialize-css Now, I need to include the CS ...

I can't seem to get the npm run dev command to work properly after setting up

After successfully setting up React JS with Vite and running npm i, I encountered an error when trying to run npm run dev: > [email protected] dev > vite E:\nasheednaldo\node_modules\rollup\dist\native.js:64 ...

ng-click not functioning correctly within templateUrl directive

Apologies if this appears to be a silly question, but I am new to Angular. I am facing an issue with an ng-click event that was functioning correctly until I moved the code into a directive. I suspect it has something to do with the scope, but I'm una ...