JS - SyntaxError: Identifier 'financeManager' has already been declared [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
const company = "Big Bucks co.";
let profit = 900;
let financeManager = "Richard";
if (profit < 1000) {
var richardFired = true;
var financeManager = "Fay";
}
console.log(company);
console.log(financeManager);
console.log(richardFired);
Hey, I'm practicing my code! I'm trying to figure out why I am getting
SyntaxError: Identifier 'financeManager' has already been declared
I want the console.log(financeManager); to log Fay, but it is logging Richard.
Thanks, in advance!

remove var inside if, you're declaring it again

Related

does anyone know how to correct this code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
function tipCalculator(nonTipTotal)
{
var totalWithTip = nonTipTotal * 15;
console.log(`You should pay {totalWithTip} including tip`)
}
function tipCalculator();
It's supposed to print out the statement of the total with the tip included
Maybe this?
function tipCalculator(nonTipTotal) {
const totalWithTip = nonTipTotal * 1.15;
console.log(`You should pay ${totalWithTip} including tip`)
}
const billTotal = 25 // get your bill input somehow - depends how this runs
tipCalculator(billTotal);
You are missing the $ symbol before the opening curly bracket. It should be ${totalWithTip} instead of {totalWithTip}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

How do I make an alert() that prints out the value of a variabile? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm trying to make an alert, that prints the value of a variabile, here is my attempt.
var username = prompt("I'm LaunchBot, what's your name?");
var print = alert() ;
alert() is a function. It take a parameter between the parenthesis. So just insert your variable username between them:
var username = prompt("I'm LaunchBot, what's your name?");
alert(username) ;
As suggested in the comment alert() doesn't return anything so do not add a variable assignment before.

Javascript backgroundColor works on some computers, not on others? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This part of javascript code works on my home computer, but doesn't at work. Also, my colleague tested it and it doesn't work on her home computer?!
function klikNaX(x, y, z) {
var u = document.getElementById(z);
var u2;
u2 = u.style.backgroundColor;
document.getElementById("test").innerHTML = (z + " " + u2);
}
The problem seems to be with this part
u.style.backgroundColor;
Its not a problem of style.backgroundColor, instead please check if 'u' is a valid node and not undefined.
And try setting a color to u.style.backgroundColor = 'green'

Why does JavaScript get this comparison wrong? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This is happening on an angular application I'm building. If a user enters 80 into an HTML input, it always seems to get this comparison wrong.
var x = '80';
var y = 150.9800;
/* Returns incorrect answer */
if (parceFloat(x) < y) {
return true;
} else {
return false;
}
You need to use ParseFloat() not parceFloat() ...
parceFloat is not an existing function.
parceFloat() is not a function, the function is parseFloat()
A simple typo is all the error there is.

Javascript String.replace [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Can someone please explain why this code isn't working?
(it has been simplified for this example)
$(document).ready(function () {
var test = 'broken';
test = test.replace('broken','working');
console.log(test); // working
var field = $('[for="tournament_name"]').html();
console.log(field); // Tournament Name:
console.log(typeof field); // string
field = field.relpace(':',''); // Uncaught TypeError: undefined is not a function
});
I don't understand why it is saying replace() is undefined?
I did read through the docs, what am I missing here?
Maybe it's a typo:
relpace --> replace

Categories

Resources