Mines better.
function calculator(num1, num2, operationString) { if (operationString == "-") { return num1 - num2; } if (operationString == "+") { return num1 + num2; } if (operationString == "*") { return num1 * num2; } if (operationString == "/") { return num1 / num2; } } calculator(1, 2, "+");
// The operation with the number "1" goes firstvar add1 = 0var add2 = 0var minus1 = 0var minus2 = 0var divide1 = 0var divide2 = 0var times1 = 0var times2 = 0//change the numbers in the varibles aboveconsole.log("Addition" , add1 + add2) //Additionconsole.log("Subtraction", minus1-minus2) //Subtractionconsole.log("Division" , divide1/divide2) //Divisionconsole.log("Multiplication" , times1*times2) //Multiplication- function calculator(num1, num2, operationString) {
- if (operationString == "-") {
- return num1 - num2;
- }
- if (operationString == "+") {
- return num1 + num2;
- }
- if (operationString == "*") {
- return num1 * num2;
- }
- if (operationString == "/") {
- return num1 / num2;
- }
- }
- calculator(1, 2, "+");
//
- //
Make a file get downloaded.
function download(filename, text) {
var element = document.createElement("a");
element.setAttribute(
"href",
"data:text/plain;charset=utf-8," + encodeURIComponent(text)
);
element.setAttribute("download", filename);
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
window.onload = function() {
var text = "downloaded file";
var filenames = "file";
var filename = filenames + ".txt";
download(filename, text);
}