Code A Simple Game In C++ , Java And Javascript | Comparison

TEC Study
4 min readApr 20, 2021

--

We will compare
between the 3 most common programming languages C++ , Java and Javascript,
by coding a “geuss number game”.

Code A Simple Game In C++ , Java And Javascript | Comparison

Whenever I start learning a new programming language, I focus on defining variables, writing a statement, and evaluating expressions, once I have a general understanding of those concepts, I can usually figure out
the rest on my own.

Most programming languages have some similarities, so once you know one programming language, learning the next one is a matter of figuring out the unique details and recognizing the differences.

To help me practice a new programming language, I like to write a few test programs. One sample program I often write is a simple "guess the number" game, where the computer picks a number between one and 100 and asks me to guess it.

The program loops until I guess correctly. This is a very simple program, as you can see using pseudocode like this:

1. The computer picks a random number between 1 and 100.

2. Loop until I guess the random number.

3. The computer reads my guess.

4. It tells me if my guess is too low or too high.

This "guess the number" game is a great introductory program when learning a

new programming language

because it exercises several common programming concepts in a pretty

straightforward way.

By implementing this simple game in different programming languages, you

can demonstrate some core concepts and compare each language’s details.

So by coding this game with the 3 defferent launguages it would give us the opportunity to compare them while they are doing the same thing,
you will see that learning the next programming language is mostly about learning its differences.

Let’s start coding our game now… take in mind that I’ll skip some of the

surrounding code, such as assigning temporary variables,
to focus on how the basics are similar or different.

The first thing to do is making the computer picks a random number between one and 100.

And that the code to do that in each language

You can see a lot of similarities here. C++ and Javascript generate a random
number with a function like Rand that you can put into a range on your own.

Otherwise Java use a special function where you can specify the range for the random value.

In the second step we will write a code to Loop until I guess the random number

Loops are usually done with a flow-control block such as while or do-while. The JavaScript implementation doesn’t use a loop and instead updates the HTML page until the user guesses the correct number. and here u can see similarities

between C++ and Java.

And now as a third step we will make the computer reads our guess…

That’s the code for that in each language

Different programming languages handle input differently. So there’s some variation here.
And like we can see JavaScript reads values directly from an HTML form.

By moving to the last step, we wrote the codes to make the computer tell us
if our guess is too low or too high.

Comparisons are fairly consistent across these C-like programming languages,

usually through an if statement. There’s some variation in how each programming language prints output, but the print statement remains

recognizable across each sample.

Another information u should know that many programming languages

adopted a similar programming syntax of C including the 3 we have talked

about in this vedio,
And C is an early general-purpose programming language, created in 1972 at

Bell Labs by Dennis Ritchie, and it proved popular and quickly became a

standard programming language on Unix systems.

https://youtu.be/7mv6aWY8bn4

--

--