OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to update a variable value with a new value if conditions are met?

  • Thread starter Thread starter Alexandru Baginean
  • Start date Start date
A

Alexandru Baginean

Guest
I want to create a simple calculator for a simple challenge I found on the internet which calculates the tip you leave for a bill depending on what the value of that bill is, if its between 50 and 300 the tip percentage should be 20%, otherwise it should be 15%.

I want to change the current value of X with the new value inside my If statement once the conditions have been met but after I run the code the initial value is taken.

I've tried to define X inside the IF statement but still not working.

Can somebody help me with a hint to what I'm doing wrong so I can fix it by myself?

Thank you!

Code:
let bill = 300;
let x = 0;
let percentage = x;
let tip = (percentage / 100) * bill;
if (bill >= 50 && bill <= 300) {
x = 20;
else {
x = 15;

and I've tried it like this:

Code:
let bill = 300;
let percentage = x;
let tip = (percentage / 100) * bill;
if (bill >= 50 && bill <= 300) {
let x = 20;
else {
let x = 15;

<p>I want to create a simple calculator for a simple challenge I found on the internet which calculates the tip you leave for a bill depending on what the value of that bill is, if its between 50 and 300 the tip percentage should be 20%, otherwise it should be 15%.</p>
<p>I want to change the current value of X with the new value inside my If statement once the conditions have been met but after I run the code the initial value is taken.</p>
<p>I've tried to define X inside the IF statement but still not working.</p>
<p>Can somebody help me with a hint to what I'm doing wrong so I can fix it by myself?</p>
<p>Thank you!</p>
<pre><code>let bill = 300;
let x = 0;
let percentage = x;
let tip = (percentage / 100) * bill;
if (bill >= 50 && bill <= 300) {
x = 20;
else {
x = 15;
</code></pre>
<p>and I've tried it like this:</p>
<pre><code>let bill = 300;
let percentage = x;
let tip = (percentage / 100) * bill;
if (bill >= 50 && bill <= 300) {
let x = 20;
else {
let x = 15;
</code></pre>
 

Latest posts

L
Replies
0
Views
1
lagnaoui jihane
L
E
Replies
0
Views
1
Eduard Dubilyer
E
Top