Giter Club home page Giter Club logo

curso-javascript-projeto-calculadora-clone's Introduction

Calculadora JavaScript

Hcode Treinamentos

Calculadora desenvolvida como exemplo do Curso Completo de JavaScript na Udemy.com.

Projeto

Calculadora

curso-javascript-projeto-calculadora-clone's People

Contributors

cursohcode avatar joaohcrangel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

curso-javascript-projeto-calculadora-clone's Issues

Secão 2 - aula 12.C07 Adicionando evento click -ERRO

class CalcController {
constructor(){
this._locale = 'pt-BR';
this._displayCalcEl = document.querySelector("#display");
this._timeEl = document.querySelector("#hora");
this._dateEl = document.querySelector("#data");
this._currentDate;
this.initialize();
this.initButtonsEvents();

}
  
initialize(){

    setInterval(()=>{
        this.displayDate = this.currentDate.toLocaleDateString(this._locale);
        this.displayTime = this.currentDate.toLocaleTimeString(this._locale);
    }, 1000);    

}

addEventListenerAll(element, events, fn){
     events.split(' ').forEach(event =>{
         element.addEvenrListener(event, fn, false);
     });
}

initButtonsEvents(){
    let buttons = document.querySelectorAll("#buttons > g, #parts > g");
    buttons.forEach((btn, index)=>{
        this.addEventListenerAll(btn, "click drag mouseover", e =>{
            console.log(btn.className.baseVal.replace("btn-",""));
        })
    })
}
get displayTime(){
    return this._timeEl.innerHTML;
}
set displayTime(value){
    return this._timeEl.innerHTML = value;
}

get displayDate(){
    return this._dateEl.innerHTML;
}
set displayDate(value){
    return this._dateEl.innerHTML = value;
}

get displayCalc(){
    return this._displayCalcEl.innerHTML;
}
set displayCalc(value){
    this._displayCalcEl.innerHTML = value;
}
get currentDate(){
    return new Date();
}
set currentDate(value){
    this._currentDate = value;
}

}

Erro na aula C11

@anthony1910 @joaohcrangel @glauciodaniel

Boa noite, favor verificar qual erro nesse codigo no metodo this._Operation.push(value) não funciona.

class CalcController {

constructor() {
    this._locale = 'pt-BR';
    this._Operation = [];
    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);
};

setDisplayDateTime(){
    this.displayDate = this.currentDate.toLocaleDateString(this._locale);
    this.displayTime = this.currentDate.toLocaleTimeString(this._locale);
};

addEventListenerAll(element, events, fn){
   
    events.split(' ').forEach(event =>{
        element.addEventListener(event,fn,false);
    });

};

clearAll(){
    this._Operation = [];
};

clearEntry(){
    this._Operation.pop(); 
}

setError(){
    this.displayCalc = "Error";
}

getLastOperation(){
    return this._Operation[this._Operation-1];
}

isOperator(value) {
  return (['+','-','/','*','%'].indexOf(value) > - 1); 
    
}


addOperation(value){
    
    console.log(value); 
    console.log(this.getLastOperation());
    console.log(this.isOperator());
    
    if(isNaN(this.getLastOperation())){
        if (this.isOperator(value)) {
            this._Operation[this._Operation.length - 1] = value;
        } else if (isNaN(value)) {
           console.log(value);
        } else {
            this._Operation.push(value);
        }
        } else{
        let newValue = this.getLastOperation().toString() + value.toString();
        this._Operation.push(newValue);
    }
}

execButton(value) {
    switch (value) {
        case 'ac':
            this.clearAll();
            break;
        case 'ce':
            this.clearEntry();
            break;
        case 'soma':
            this.addOperation('+');   
            break;
            
        case 'subtracao':
            this.addOperation('-');
            break;
        
        case 'multiplicacao':
            this.addOperation('*');
            break;
        
        case 'divisao':
            this.addOperation('/');
            break;
        
        case 'porcento':
            this.addOperation('%');
            break;
        
        case 'igual':
            this.addOperation('=');
            break;

        case 'ponto':
            this.addOperation('-');
        break;

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                this.addOperation(parseInt(value));
                
                break;

        default:
            this.setError();
            break;
    }
}

initButtonsEvents(){
    let buttons = document.querySelectorAll("#buttons > g, #parts > g");
    buttons.forEach((button,index)=>{
      
        this.addEventListenerAll(button,"click drag" , e=>{
            let txtbutton = (button.className.baseVal.replace("btn-",""));
            this.execButton(txtbutton);
       });

       this.addEventListenerAll(button, "mouseover mouseup mousedown", e=> {
        button.style.cursor = "pointer";
    });

    });     
};  
    
get displayTime() {
    return this._timeEl.innerHTML;
}
set displayTime(value) {
    this._timeEl.innerHTML = value;
}
get displayDate() {
    return this._dateEl.innerHTML;
}
set displayDate(value) {
    this._dateEl.innerHTML = value;
}
get displayCalc(){
    return this._displayCalcEl.innerHTML;
}
set displayCalc(value){
 this._displayCalcEl.innerHTML = value;
}
get currentDate(){
    return new Date();
}
set currentDate(value){
    this._currentDate.innerHTML = value;
}

}

Aula 14 - calculadora hcode - array não faz o push

Meu array:
addOperation(value){
this._operation.push(value);
console.log(this._operation);
}
Não fez o push para o array.
Acredito que meu código esta igual a aula número 14, porem o value deveria vir de initButtonsEvents().
Este não deu certo. Tentei, revisei, as aulas, igual.. talvez tenha esquecido ou feito algo errado quem puder ajudar. vlw

`

class CalcController{
constructor(){
this._locale='pt-BR';
this._operation=[];
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);
};

setDisplayDateTime(){
    this.displayDate=this.currentDate.toLocaleDateString(this._locale,{day:"2-digit",month:"long",year:"numeric"});
    this.displayTime=this.currentDate.toLocaleTimeString(this._locale); 
};

addEventListenerAll(element, events, fn){
    events.split(' ').forEach(event=>{
       element.addEventListener(event,fn,false); 
    });
};

clearAll(){

   this._operation=[];
}
clearEntry(){
    this._operation.pop();
}
setError(){
    this.displayCalc="Error";
}

 addOperation(value){       
    this._operation.push(value); 
    console.log(this._operation);
}

  
execBtn(value){
    switch(value){
        case 'ac':
            this.clearAll();
            break;
        case 'c':
            this.clearEntry();
             break;
        case 'soma':
        
            break;
        case 'subtracao':
        
            break;
        case 'divisao':
        
            break;
        case 'multiplicacao':
        
            break;
        case 'porcento':
        
            break;
        case 'igual':
        
            break;

        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            this.addOperation(parseInt(value));
            break;
         default:
            this.setError();
            break;
    }
}

initButtonsEvents(){
    let buttons=document.querySelectorAll("#buttons > g, #parts > g");
    buttons.forEach((btn,index)=>{
        this.addEventListenerAll(btn, "click drag mouseover", e => {
            console.log(btn.className.baseVal.replace("btn-",""));
        });
        this.addEventListenerAll(btn, "mouseover mouseup mousedown",e=>{
            let textBtn=btn.style.cursor="pointer";
            this.execBtn(textBtn);
        });
    });
}


get displayTime(){
    return this._timeEl.innerHTML;
}

set displayTime(value){
    return this._timeEl.innerHTML=value;

}
get displayDate(){

    return this._dateEl.innerHTML;
}

set displayDate(date){

    return this._dateEl.innerHTML=date;
}

get displayCalc(){
    return this._displayCalcEl.innerHTML; 
}
set displayCalc(valor){
    this._displayCalcEl.innerHTML=valor;
}
get currentDate(){
    return  new Date();
}
set currentDate(data){
    this._currentDate=data;
}

}

`

Erro na aula C09

Boa tarde a todos.

Qualquer click meu retorna "error".
Eu já revisei o código algumas vezes e não encontrei o motivo.
Podem me ajudar?

Abs e Feliz Natal!

class CalcController{

constructor(){

    this.operation = [];
    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);
    });
}

clearAll(){

    this._operation = [];

}

clearEntry(){

    this._operation.pop();

}

addOperation(value){

    this._operation.push(value);
    console.log(this._operation);
}

setError(){
    this.displayCalc = "Error";
}

execBtn(value){

    switch (value) {
        case 'ac':
            
            break;
        case 'ce':
            
            break;
        case 'soma':
            
            break;
            
        case 'subtracao':
            
            break;
        
        case 'multiplicacao':
            
            break;
        
        case 'divisao':
            
            break;
        
        case 'porcento':
            
            break;
        
        case 'igual':
            
            break;

        case 'ponto':
            
        break;

        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            this.addOperation(parseInt(value));
            
            break;

        default:
            this.setError();
            break;
    }
}


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.execBtn();
        });

        this.addEventListenerAll(btn, "mouseover mouseup mousedown", e =>{

            btn.style.cursor = "pointer";
        });
    });

    
}

setDisplayDateTime(){

    this.displayDate = this.currentDate.toLocaleDateString(this._locale, {
        day: "2-digit",
        month: "short",
        year: "numeric"
    });
    this.displayTime = this.currentDate.toLocaleTimeString(this._locale);
}

get displayDate(){

    this._dateEl.innerHTML
}

set displayDate(value){

    return this._dateEl.innerHTML = value;
}

get displayTime(){

    this._timeEl.innerHTML
}

set displayTime(value){

    return this._timeEl.innerHTML = value;
}

get displayCalc(){

    return this._displayCalcEl.innerHTML;
}

set displayCalc(valor){
    this._displayCalcEl.innerHTML = valor;
}

get currentDate(){
    return new Date();
}

set currentDate(value){
    this._currentDate = value;
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.