Require assistance in getting a slider operational

Hello there! I could really use your assistance with this code. I have been trying to make it work using JavaScript, but I'm determined not to incorporate any external JS files.

Here is the snippet of JavaScript code I am working with:

"use strict";
var $ = window.jQuery;

// BEDROOM_RATES object
var BEDROOM_RATES = {
    b1 : 99,
    b2 : 119,
    b3 : 139,
    b4 : 169,
    b5 : 189,
    b6 : 229
};
var PER_BATHROOM = 20; 

// Rest of the JavaScript functions and event handlers go here...

Also, below is the CSS styling for a front slider that you can check out in action on this demo link:

Check demo working on 
http://getondesk.com/demo/zenclean/

Its a front slider

I want to avoid external JavaScript files altogether and rely solely on inline scripts for functionality. Can anyone guide me on how to achieve this? Your help would be greatly appreciated!

Answer №1

Here's a creation of mine that I put together in about 30 minutes xD. Please check it out on Code Pen. Make sure to view it in FULL SCREEN MODE:

var room = document.getElementById("bedNumber").getContext("2d");
var stay = document.getElementById("stayNumber").getContext("2d");

room.beginPath();
room.fillStyle = "red";
room.fillRect(20, 0, 30, 10);

stay.beginPath();
stay.fillStyle = "red";
stay.fillRect(20, 0, 30, 10);

var RoomNumber = 0;
var StayNumber = 0;
var Lux = 0;

function chose(context, event) {
  var X = event.clientX - 80;
  if (context == "room") {
    room.beginPath();
    room.fillStyle = "red";
    room.clearRect(0, 0, 1000, 50);
    room.fillRect(X, 0, 30, 10);
    RoomNumber = X / 2;
  } else {
    stay.beginPath();
    stay.fillStyle = "red";
    stay.clearRect(0, 0, 1000, 50);
    stay.fillRect(X, 0, 30, 10);
    StayNumber = X;
  }
  Price();
}

function addLuxury(lux) {
  Lux = lux * 50;
  Price();
}

function Price() {
  var Total = RoomNumber + StayNumber + Lux;
  document.getElementById("total").innerHTML = "BUY ROOM(S) FOR " + Total + "$";
}
#slider {
  background-color: rgba(0, 0, 0, 0.3);
  width: 600px;
  height: 400px;
}
h1 {
  color: white;
  text-align: center;
}
u {
  color: white;
}
canvas {
  border: 2px solid black;
  margin-left: 50px;
  background-color: white;
}
button {
  background-color: #0099ff;
  border-radius: 25px;
  margin: 8px;
}
#total {
  background-color: #6666ff;
  border-radius: 25px;
  text-align: center;
}
<body>
  <div id="slider">
    <u><h1>Hotel Rooms For Good Price</h1></u>
    <br/>ROOMS :
    <canvas id="bedNumber" width="500" height="10" onclick="chose('room', event)"></canvas>
    <br/>
    <br/>STAY :
    <canvas id="stayNumber" width="500" height="10" onclick="chose('stay', event)"></canvas>
    <br/>
    <u><h3>Luxury</h3></u>
    <button onclick="addLuxury(0)">LUXURARY : BAD
      <br/>+0$ per/D</button>
    <button onclick="addLuxury(1)">LUXURARY : OK
      <br/>+75$ per/D</button>
    <button onclick="addLuxury(2)">LUXURARY : WOW
      <br/>+150$ per/D</button>
    <button onclick="addLuxury(3)">LUXURARY : BEST
      <br/>+215$ per/D</button>
    <br/>
    <br/>
    <br/>
    <button id="total">BUY ROOM(S) FOR $0</button>
  </div>
</body>

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

I'm looking to create a unique combination of a line and bar chart. Any advice on how to

When I stretch my Scale like this determineDataLimits: function () { var min = Math.min.apply(null, this.chart.data.datasets[0].data) console.log(this) console.log(defaultConfigObject) Chart.options.scales.rightSide.ticks.min = function ...

Determining if a user is already logged in from a different device using express-session

After a user logs in, I assign the username to their session with the code: req.session.username = "...."; This identifies the session with a username, but now I need to figure out how to detect if this same username is already logged in from another dev ...

Transfer information from the client to the server using AJAX and PHP by

When attempting to post a JavaScript variable called posY to a PHP file, an error occurred with the message: Notice: Undefined index: data in C:\xampp\htdocs\Heads_in_the_clouds\submitposY.php The posY variable is defined in the JavaSc ...

What is the best way to implement coding for portrait styles specifically on the Kindle Fire device?

Any recommendations on how to specifically code the styles for portrait orientation solely on the Kindle Fire device? ...

Perform simple arithmetic operations between a number and a string using Angular within an HTML context

I'm stuck trying to find a straightforward solution to this problem. The array of objects I have contains two values: team.seed: number, team.placement: string In the team.placement, there are simple strings like 7 to indicate 7th place or something ...

Issue with rendering an object's property using EJS

Trying to include the author's username in reviews within an ejs template for my app. The following code snippet: <%= review.author %> is functioning correctly and displays: { _id: 5eff6793e7f26811e848ceb1, username: 'mike', __v: 0 ...

Upon updating my application from Angular 14 to 16, I encountered an overwhelming number of errors within the npm packages I had incorporated

After upgrading my angular application from v14 to v16, I encountered numerous peer dependencies issues, which led me to use the --force flag for the upgrade process. However, upon compiling, I am now faced with a multitude of errors as depicted in the scr ...

When attempting to check and uncheck checkboxes with a specific class, the process fails after the first uncheck

I have a set of checkboxes and one is designated as "all." When this box is clicked, I want to automatically select all the other checkboxes in the same group. If the "all" box is clicked again, I would like to deselect all the other checkboxes. Currently ...

Rendering illuminated component with continuous asynchronous updates

My task involves displaying a list of items using lit components. Each item in the list consists of a known name and an asynchronously fetched value. Situation Overview: A generic component named simple-list is required to render any pairs of name and va ...

Utilize vue.js to save the components of an object

data() { return: { user: {}, userName: "", userAge: "" } }, methods: { saveUserName: function() { this.userName = this.newUserName; this.$refs.userNameModal.hideModal(); this.$ ...

What is the proper way to utilize CSS animation delays in order to design a collapsible HTML container?

I'm trying to implement responsive CSS animation delay to create an accordion effect when a user clicks on an arrow associated with a table, all without using JavaScript and only utilizing HTML/CSS. Check out the mobile view in action here: https://w ...

What is the best way to incorporate three divs into a single line while maintaining a responsive design

Struggling with adding a logo above a login form? As a PHP developer without design expertise, achieving a responsive layout like the image below may seem daunting. To create this layout, consider using the following code: <style> .container { ...

What are the steps to incorporating the League Gothic font into my website design?

Is there a way to incorporate League Gothic font into my website design? Visit the League Gothic GitHub repository Appreciate any guidance on this matter, ...

In what way can you establish a boundary for a border?

My goal is to create a 10x10 grid with randomly placed black boxes, but I am facing an issue in my game setup: Currently, the 5 black boxes are generated randomly in a row, sometimes exceeding the border and breaking the continuity. I would like to establ ...

Changing the value in a URL String using JavaScript

I am in possession of a String that contains a URL resembling the following: var url ="http://ispeakphone.com/checkout/cart/add/uenc/aHR0cDovL2lzcGVha3Bob25lLmNvbS9zYW1zdW5nL3NhbXN1bmctZ2FsYXh5LXMvZ2FsYXh5LXM5LXBsdXMuaHRtbA,,/product/619/form_key/foxmD7jg ...

Determine the hour difference between two provided dates by utilizing the date-fns library

My API returns a "datePublished" timestamp like this: "2019-11-14T14:54:00.0000000Z". I am attempting to calculate the difference in hours between this timestamp and the current time using date.now() or new Date(). I am utilizing the date-fns v2 library fo ...

Unable to load routes from ./app.js in the file ./src/routes/index.js

Just dipping my toes into the world of nodejs. I recently moved all my routes from app.js to a separate file located at PROJECT_DIR/src/routes/index.js. However, when I try to open the page in my browser, it displays "Cannot GET /wines". Below are snippets ...

Mastering parameter passing in Node.js functions: A comprehensive guide

As I embark on my journey with node js (refer to the question), please be patient as I navigate through this new territory. To clarify my query, I have developed a function to be invoked in another JS file: exports.test = function(req, res){ connection ...

Preventing the upload of empty images in an angular application

When selecting multiple images for upload, I sometimes need to make changes or delete the chosen images before actually uploading them. However, if any of the selected images have a size of 0B, I want to stop the upload process for all images, not just the ...

What's stopping the error exception from showing up on the client side?

Here's the scenario: I have an action method called SavePoint that contains some logic and throws a System.ArgumentException with the message "Error, no point found". Additionally, there is an ajax function named saveFeature which makes a GET request ...