0

I have a mini project that I need to make a simple calculator with a history. In a part of this project, it should be deleted if one of the history items is clicked, but I got an error while making this. Do you have a solution to solve this error and a theory? About my solution to delete items you have

Type 'string[]' is not assignable to type 'string'.

let text: string = "";
const historyArrey: Array<String> = [];
let equal = document.getElementsByClassName("btn-blue");

equal[0].addEventListener("click", () => {
    let response = eval(text);
    let historyBox = document.getElementById("history");

    (<HTMLInputElement>document.getElementById('screen')).value = response;

    historyArrey.push(text + "=" + response);
    console.log(historyArrey);

    if (historyBox) {
        historyBox.innerHTML = historyArrey.map((i) => {//error
            return "<p onclick='removeItem()'>" + { i } + "</p>"
        });
        historyArrey.join("<br/>")
    }
})

0

1 Answer 1

1

Problem

Your join here:

historyBox.innerHTML = historyArrey.map((i) => {
  return "<p onclick='removeItem()'>" + { i } + "</p>"
});
historyArrey.join("<br/>")

does nothing.

Solution

You have to join the array before assigning

historyBox.innerHTML = historyArrey.map((i) => {
  return "<p onclick='removeItem()'>" + { i } + "</p>"
}).join("<br/>");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.