Server-side PHP instead-JavaScript

Assignment Help Basic Computer Science
Reference no: EM133217100

<div id="tip-calculator">

</div>

*,

*:before,

*:after {

margin: 0;

padding: 0;

box-sizing: border-box;

}

html {

font-size: 100%;

}

body {

width: 100%;

height: 100vh;

overflow: hidden;

display: grid;

place-items: center;

background: rgb(12, 141, 195);

font-family: "Lato", sans-serif;

font-weight: 400;

line-height: 1.75;

}

#tip-calculator

{

width: 80%;

max-width: 350px;

padding: 1rem;

background: white;

border-radius: 0.3rem;

}

<h1>Tip Calculator</h1>

h1{

background: rgb(11, 108, 161);

color: white;

font-size: 27px;

text-align: center;

margin-top: -17px;

margin-left: -17px;

margin-right: -17px;

}

<form id="form">

<label for="bill" class="h3">

Bill: $

<input type="number" min="0" step="0.01" value="50" name="bill" id="bill" />

</label>

 

<label for="people" class="h3">

People:

<input type="number" min="1" step="1" value="1" name="people" id="people" />

</label>

 

<label for="percentage" class="h3">

Tip Percentage:

<span id="percentage-output"></span>

<input type="range" min="0" max="100" step="1" value="20" name="percentage" id="percentage" />

</label>

</form>

 

form {

border-top: 1px solid hsl(149, 31%, 25%);

}

label {

display: block;

}

input[type="number"] {

width: 100%;

max-width: 4em;

background: none;

border: none;

font-size: 20px;

color: rgb(26, 64, 237);

border-bottom: 1px dashed black;

-moz-appearance: textfield;

}

input[type="number"]::-webkit-outer-spin-button,

input[type="number"]::-webkit-inner-spin-button {

-webkit-appearance: none;

margin: 0;

}

#people {

max-width: 3em;

}

 

I designed the range slider using the CSS codes below.

#percentage {

-webkit-appearance: none;

width: 100%;

margin: 2rem 0;

height: 10px;

background: hsl(193, 94%, 34%);

border-radius: 3px;

}

#percentage::-webkit-slider-thumb {

-webkit-appearance: none;

appearance: none;

width: 30px;

height: 30px;

border-radius: 50%;

border: 2px solid rgb(5, 47, 156);

background: hsl(255, 14%, 66%);

cursor: pointer;

}

<div id="output" class="h3"></div>

.h3 {

margin: 1.38rem 0;

font-size: 1.424rem;

}

#output {

text-align: center;

box-shadow: 0 0 20px rgba(0,139,253,0.25);

padding: 10px;

color: rgb(9, 73, 171);

}

const form = document.getElementById("form");

const totalBill = document.getElementById("bill");

const totalPeople = document.getElementById("people");

const tipPercentage = document.getElementById("percentage");

const percentageOutput = document.getElementById("percentage-output");

const output = document.getElementById("output");

All information will be stored in the "tipPercentage" function. The value of this function is displayed in the display using "innerText" at the end of all.

// event listeners

form.addEventListener("change", calculateTip);

tipPercentage.oninput = calculateTip;

 

//I have added a manual formula to calculate the tip in the "calculate Tip" function.

function calculateTip() {

//Manual tip calculation formula stored in "dollar suPerPerson" constant

const dollarsPerPerson = (

(totalBill.value * (tipPercentage.value / 100)) /

totalPeople.value

).toFixed(2); //The toFixed() method converts a number to a string.

displayTip(`${dollarsPerPerson}`);

displayPercentage();

}

 

The condition here is that if the value of 'totalPeople' is more than 1, then the text "Each person should tip" can be seen. If the value of 'totalPeople' is 1, then the text "You should tip" will appear.

function displayTip(totalPerPerson) {

output.innerText =

totalPeople.value > 1

? `Each person should tip ${totalPerPerson}`

: `You should tip ${totalPerPerson}`;

}

Now with the help of 'innerText', the value of "tipPercentage" is displayed on the webpage as a result.

function displayPercentage() {

percentageOutput.innerText = `${tipPercentage.value}%`;

}

// on load

calculateTip();

Rewrite the program to use server-side PHP instead. The syntax of PHP is similar to that of JavaScript; keep in mind the following differences:

PHP uses the print function instead of JavaScript's document.write function.

PHP prefixes a dollar sign ($) on every variable name.

PHP encloses its code in <?php and ?> tags, where JavaScript uses <script> and </script?>.

JavaScript and PHP provide different function libraries. For example, the JavaScript Math.round() and the PHP round() functions work differently.

JavaScript uses "+" to concatenate strings while PHP substitutes values for variables inside a string. With PHP, you cannot calculate and concatenate in one statement.

Reference no: EM133217100

Questions Cloud

Should patients be incorporated as members : Should patients be incorporated as members of the healthcare team and participate in team discussions of their current health status and treatment options?
How does an understanding of your strengths : How do you relate to statement? How does an understanding of your strengths relate to self knowledge and self invention?
Defense and planning : BADM 200 Hudson Valley Community College, You would love to share this juicy news with other department members, for their own defense and planning. Should you?
What are main points made about topic by ross : What are main points made about topic by Ross? What does she suggest as a better way to approach our need to be grammar police (To Correct and Serve)
Server-side PHP instead-JavaScript : Rewrite the program to use server-side PHP instead. The syntax of PHP is similar to that of JavaScript;
Describe two people you know from two different cultures : CA 235 Park University, Describe two people you know from two different cultures. Compare or contrast five characteristics the people have prompted
What benefits can you see in using these 5 steps : What benefits can you see in using these 5 steps and Why is it important to be thorough when making recommendations?
Canadian tire-brand audit : Set the context for the audit. Show you understand what business your organization is in.
Threats to our national survival : The Cold War is related to the IC's transition from focusing on "threats to our national survival" to "threats to the safety of all Americans.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd