I'm so sorry for asking but where should I insert or save C++.:rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::rolleyes:
I'm skilled in html css and javascript but I don't get this.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title>Test</title>

<script type="text/javascript">
function test()
{
alert("NIET KLIKKEN VERDOMME")
}
</script>

<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()


m=checkTime(m)
s=checkTime(s)
document.getElementById('txt').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}

function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
</script>

</head>

<body bgcolor="#FFFFE1" onload="startTime()">
<center><div id="txt"></div>

<script type="text/javascript">
var d = new Date()
var time = d.getHours()
if (time>5 && time<12)
{
document.write("Good morning!")
}
else if (time>11 && time<18)
{
document.write("Good day!")
}
else if (time>17 && time<24)
{
document.write("Good evening!")
}
else
{
document.write("Good night!")
}
</script></center>

<br/>
<center>
<table border="0" width=50%>
<tr>
<center><input type="button" value="klikken" onclick="test()"></center>
</tr>
<tr>

</tr>

</table>
</center>

</body>

Dani AI

Generated

For : C++ is not something you "drop into" an HTML file the way you do JavaScript. Browsers execute JavaScript (and WebAssembly), not native C++ binaries. That is the key difference missing from the thread; was right to ask what you actually want to do, and was correct to point out the mismatch between the HTML/JS you posted and C/C++ expectations.

Three practical paths depending on your goal:

  • Run a standalone C++ program on your machine (desktop app): save source as a .cpp file, compile it with a compiler (g++, clang or MSVC) and run the produced executable. Typical workflow: edit source, compile, fix compile errors, run. Use an IDE (Visual Studio, Code::Blocks) or a command-line toolchain.

  • Make a server-side component that your HTML/JS calls: compile a C++ program to run on the server and expose an HTTP/JSON endpoint (CGI/FastCGI or a small web server using a C++ web framework). The browser front end talks to that server code with Ajax/fetch.

  • Run C++ logic in the browser: compile C++ to WebAssembly so it can be loaded and called from JavaScript. Modern toolchains and examples are at the WebAssembly docs and the Emscripten project (see MDN WebAssembly and Emscripten).

Troubleshooting notes: common beginner problems are syntax/compile errors, missing compiler on PATH, wrong file extension, or forgetting execute permissions on Unix. If the goal is a web page feature, using JavaScript is usually simplest; only choose server-side C++ or WebAssembly when you need native performance or existing C++ libraries. For C++ language reference, see cppreference.

Recommended Answers

All 2 Replies

I still don't understand what you want to do. Do you want to write a comparable version of the posted code in C++? Do you want to insert some C++ code into the code you currently posted? What exactly do you want to do?

I still don't understand what you want to do.

I agree. You may be skilled in HTML and CSS, but this is a C/C++ board. You post code here, not HTML/CSS markup language.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.