//wow this practice is awesome and hard and intense, it's great!
//Main function
function main() {
/* var input1 = readLine();
var arr1 = input1.split(" ");
print(capitalized(arr1));
print(capitalA(arr1));
print(stringSmash(arr1));
print(longestString(arr1)); */
print(calculator());
}
function calculator() {
var zoeRecord = 1.21;
var coolLamp = 2.33;
var shorts = 0.95;
var input;
var total = 0;
while ((input = readLine()) != "") {
var arr = input.split(" ");
if (arr[0] == "add") {
if(arr[1] == "record") {
total += zoeRecord;
print("record - $" + zoeRecord);
} else if(arr[1] == "lamp") {
total += coolLamp;
print("lamp - $" + coolLamp);
} else {
total += shorts;
print("shorts - $" + shorts);
}
} else {
if(arr[1] == "record") {
total -= zoeRecord;
} else if(arr[1] == "lamp") {
total -= coolLamp;
} else {
total -= shorts;
}
}
}
return "Your total is $" + total;
}
function capitalized(input) {
var newArray = [];
for (var i = 0; i < input.length; i++) {
// glad to see this new way!!!
newArray[i] = input[i].toUpperCase();
//instead of this way i originall coded it!
/* var upper = input[i].toUpperCase();
newArray.push(upper); */
}
return newArray;
}
function capitalA(input) {
var newArray2 = [];
for (var i = 0; i < input.length; i++) {
if (input[i].includes("a") == true) {
newArray2[i] = input[i].toUpperCase();
} else {
newArray2[i] = input[i];
}
}
return newArray2;
}
function stringSmash(input) {
var string = "";
for (var i = 0; i < input.length; i++) {
string += input[i];
}
return string;
}
function longestString(input) {
var longest = input[0];
for (var i = 0; i < input.length; i++) {
if (input[i].length > longest.length) {
longest = input[i];
}
}
return longest;
}
//encoding function
function...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.