Home > Software engineering >  cant get the calculator buttons to load
cant get the calculator buttons to load

Time:12-03

function createCalculatorButtons(){
const buttons_row =  6;
let added_buttons= 0;

calculator_buttons.forEach(button =>{
    if(added_buttons % buttons_row == 0){
     input_element.innerHTML  = '<div ></div>';
    }
    const row = document.querySelector(".row:last-child");
    row.innerHTML  = '<button id = "${button.name}">${button.symbol}</button>';
    added_buttons  ;                
})

the buttons are there but with the msg ${button.symbol} instead of the actual symbol

CodePudding user response:

Tried to leave this in a comment, but couldn't figure out how to get backticks to show....

When using template literals, use the backtick, not a single/double quote.

function createCalculatorButtons(){
  ...
  row.innerHTML  = `<button id = "${button.name}">${button.symbol}</button>`;
    ...             
})
  • Related