Something interesting about Templates

Okay, so if you’ve coded using JavaScript before, you’ve probably heard of template literals or strings, where basically you can input values into a string to form a sentence. An example in JavaScript would be something like this.

let apples = 5;
let oranges = 4;

console.log(`We have ${apples} apple(s) and ${oranges} orange(s)`);

So in the console, it would say, “We have 5 apple(s) and 4 orange(s)”
The ${} is where you can input variables and the `` let’s the system know that it’s a template literal or template string.

The reason I’m mentioning this is because in Gimkit, for example notifications. You concatenate using something like this.

set property: Apples;
set value: 4;

send notification;
title: Sentence
content: create text with: 
item 1. set text: "We have", 
item 2. get property Apples, 
item 3. apple(s)

Then we would get “We have 4 apples.”
And this was pretty interesting to see that the dynamic literals or strings was used like this, it never occurred to me because of the use of blocks and devices kind of scrambled it up. But it’s actually used!
[1]


  1. I didn’t know what to put as the category. :sweat_smile: ↩︎

3 Likes

I’m familiar with JavaScript.
Especially the console.log feature.
this is very interesting.
Wait, maybe you can expand this.

3 Likes

I also don’t know about the category, but I think devices would possibly be the best fit :sweat_smile:

3 Likes

there should be a “blocks” category.
That would be helpful.

And this would be easier with python btw.

2 Likes

What would it look like in Python?

I haven’t done python in years. (I may be rusty)
otherwise, I was very good at it.

1 Like
numberApples = 4

print(“We have” + numberApples + “apples!”)
2 Likes

Yeah that looks about right.
@Toothless , I think you can also use the “math” feature in python that maybe you can do this,
5 + 4 apples equals: 9! (this reminds me of preschool math videos)
Slim, can you do something like that?

2 Likes

Oh yes, I’ve heard of that way, some one told me it gets less and less useful the more variables you have to input.
(I’ve done that in JavaScript before :smile: )
[1]


  1. Why is there a solution button in devices? ↩︎

3 Likes
a = 5
b = 4
c = a + b
print(a + " + " + b + " is " + c)
2 Likes

Wouldn’t this also work with c++? (I haven’t learned c++ its too hard for me)

You can also do multiplication!

a = 3
b = 10
c = a * b
print(a + " * " + b + " is " + c)
1 Like

How much caffeine have you had? 10 * 3 does not equal 13.

(mysz reference)

for mysz

@mysz Does this joke beat yours?

An atom walks into a bar and starts a conversation with the bartender:

  • I lost an electron.

  • Are you sure?

  • I’m positive.

===============

The next day, the atom walks back into the bar and starts another conversation with the bartender:

  • I found my lost electron.

  • That’s great! Here’s a beer on the house!

  • Wow! Really?

  • No charge.

:pinch:

lol

huh. It doesn’t say its 13.

What they mean is that you wrote

Assuming that multiplying the two variable would equal c, which is equal to a + b, making this statement false, since two different operations somehow equal the same thing.

:0 i forgor.

C = A + B

A PLUS B
3 + 10
Then the print statement does this.

3 * 10 is 13

1 Like

oops, thanks for telling me tho
Screenshot 2024-09-09 7.52.05 PM

2 Likes

GTG!

1 Like