function
setup() {
createCanvas(500, 300);
textSize(16);
text(
"Click on the button to add new "
+
"values or get the lowest key"
,
20, 20);
text(
"Key:"
, 20, 60);
text(
"Value:"
, 160, 60);
key_input = createInput(
'1'
);
key_input.position(70, 50);
key_input.size(40);
val_input = createInput(
'1'
);
val_input.position(220, 50);
val_input.size(40);
setBtn = createButton(
"Add new item"
);
setBtn.position(30, 100);
setBtn.mouseClicked(createNewDict);
getBtn = createButton(
"Get Lowest Key"
);
getBtn.position(160, 100);
getBtn.mouseClicked(getLowestKey);
numDict = createNumberDict(100, 0);
}
function
createNewDict() {
clear();
let key = int(key_input.value());
let val = int(val_input.value());
numDict.set(key, val);
text(
"New key-value added to dictionary"
,
20, 160);
text(
"Key:"
, 20, 60);
text(
"Value:"
, 160, 60);
text(
"Click on the button to add new "
+
"values or get the lowest key"
,
20, 20);
}
function
getLowestKey() {
let lowestKey = numDict.minKey();
text(
"The lowest key in the dictionary is: "
+ lowestKey, 20, 200);
text(
"Key:"
, 20, 60);
text(
"Value:"
, 160, 60);
text(
"Click on the button to add new "
+
"values or get the lowest key"
,
20, 20);
}