-1
I’m having problems with a calculator design done in JS. On a specific line it says that an unexpected token has been found. I already went to Github of the course and checked their final file, and on the line where in my program (I use Visualcodeestudio) appears the error, in the other program I opened (Sublime) their code, is no error..
Grateful from now on!
class CalcController {
constructor(){
this._locale = 'pt-BR';
this._displayCalcEl = document.querySelector("#display");
this._dateEl = document.querySelector("#data");
this._timeEl = document.querySelector("#hora");
this._currentDate;
this.initialize();
this.initButtonsEvents();
}
initialize(){
this.setDisplayDateTime();
setInterval(()=>{
this.setDisplayDateTime();
}, 1000);
addEventListenerAll(element, events, fn){
events.split(' ').forEach(event => {
element.addEventListener(event, fn, false);
});
}
}
initButtonsEvents(){
let buttons = document.querySelectorAll("#buttons > g, #parts > g")
buttons.forEach((btn, index)=>{
this.addEventListenerAll(btn, "click drag", e=>{
let textBtn = btn.className.baseVal.replace("btn-",""));
});
this.addEventListenerAll(btn, "mouseover mouseup mousedown", e=>{
btn.style.cursor = "pointer";
});
});
}
setDisplayDateTime() {
this.displayDate = this.currentDate.toLocaleDateString(this._locale,{
day:"2-digit",
month: "long",
year:"numeric"
});
this.displayTime = this.currentDate.toLocaleTimeString(this._locale);
}
get displayTime(){
return this._timeEl.innerHTML;
}
set displayTime(valor){
return this._timeEl.innerHTML = valor;
}
get displayDate(){
return this._dateEl.innerHTML;
}
set displayDate(valor){
return this._dateEl.innerHTML = valor;
}
get displayCalc(){
return this._displayCalcEl.innerHTML;
}
set displayCalc(valor){
this._displayCalcEl.innerHTML = valor;
}
get currentDate(){
return new Date();
}
set currentDate(valor){
this._currentDate = valor;
}
}
Okay, I redid the code based on what you gave me, and now the error has changed xD On the Chrome console, "Uncaught Typeerror: this.addEventListenerAll is not a Function at Calccontroller.js:30" appears, meaning this.addeventlistener says it’s not a function.. kkkkk
– Geovane Pocolujco
I edited the code, see if it works now
– Thyago Dias
I put your code and it miraculously worked! o/ Could you explain to me what was wrong this time? Thanks!
– Geovane Pocolujco
Some characters were missing or left over, such as
}
and)
. Put the two codes in parallel and compare, you will notice– Thyago Dias