Как добавить суперпресс в массив в JavaScriptJavascript

Форум по Javascript
Ответить
Anonymous
 Как добавить суперпресс в массив в JavaScript

Сообщение Anonymous »

В массиве для калькулятора у меня есть: x^y (в html это будет x y ), а также x^-1 или x -1 . I can't figure out how to add it to the array for only those two buttons in the array so it displays xy and x-1 respectively instead of x < sup>y< /sup> (without the spaces, obviously) x < sup>-1< /sup>
js (missing the Слушатели и т. Д., Но дает вам представление о том, к чему я стремлюсь): < /p>
const display = document.getElementById("display");

const buttonValues = [
"Rad", "º", "x!", "(", ")", "%", "AC",
"Inv", "sin", "log", "7", "8", "9", "÷",
"π", "cos", "ln", "4", "5", "6", "x",
"e", "tan", "√", "1", "2", "3", "+",
"Ans", "EXP", "^", "0", ".", "=", "-", "+/-", "x^-1",
]

const rightSymbols = [ "÷", "x", "-", "+", "="]
const topSymbols = ["(", ")", "%", "AC"]
const leftSymbols = ["Rad", "º", "x!", "Inv", "sin", "log", "π", "cos", "ln", "e", "tan", "√", "Ans", "EXP", "^", "+/-", "x^-1",]

//A+B, A×B, A-B, A÷B
let A = 0;
let operator = null;
let B = null;

function clearAll() {
A = null;
operator = null;
B = null;
}

for (let i = 0; i < buttonValues.length; i++) {
let value = buttonValues;
let button = document.createElement("button");
button.innerText = value;

//styling button colors
if (value == "=") {
button.style.backgroundColor = "brown";
}

else if (rightSymbols.includes(value)) {
button.style.backgroundColor = "orange";
}

else if (leftSymbols.includes(value)) {
button.style.backgroundColor = "darkorange";
button.style.color = "white";
}

else if (topSymbols.includes(value)) {
button.style.backgroundColor = "orange";
button.style.color = "white";
}


Подробнее здесь: https://stackoverflow.com/questions/796 ... javascript
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»