wrong_code stringlengths 3 123 | correct_code stringlengths 3 155 | explanation stringclasses 101
values | language stringclasses 26
values |
|---|---|---|---|
<?php
// code
?> | <?php
// code
?> | Correct. | PHP |
else
print('result') | else:
print('result') | Colon after else. | Python |
for a in range(33)
print(a) | for a in range(33):
print(a) | Colon after for. | Python |
<ul><li>data<li>data</ul> | <ul><li>data</li><li>data</li></ul> | Close li. | HTML |
for i in $(ls); do echo $i; done | for i in $(ls); do echo $i; done | Correct. | Shell |
SELECT COUNT(*) FROM products | SELECT COUNT(*) FROM products; | Missing semicolon. | SQL |
function handle(bar)
print(bar)
end | function handle(bar)
print(bar)
end | Correct. | Lua |
let y: number = 'message'; | let y: string = 'message'; | Fix type. | TypeScript |
if ($a = 17) {{}} | if ($a -eq 17) {{}} | Use -eq. | PowerShell |
println('hello') | println("hello") | Double quotes. | Scala |
echo 'result' | echo 'result'; | Add semicolon. | PHP |
String name = 'info'; | String name = 'info'; | Correct. | Dart |
UPDATE items SET email='hello' WHERE role=55 | UPDATE items SET email='hello' WHERE role=55; | Add semicolon. | SQL |
y == '57' | y === 57 | Use strict equality. | JavaScript |
echo data hello | echo 'data hello' | Quote to prevent splitting. | Shell |
x = 5; if x > 3, disp('large'), end | x = 5; if x > 3, disp('large'), end | Correct. | MATLAB |
<a href='https://demo.net' target='_blank'> | <a href='https://demo.net' target='_blank' rel='noopener'> | Add rel for security. | HTML |
switch(c){{ case 29: break; }} | switch(c){{ case 29: break; default: break; }} | Add default case. | Java |
Write-Host 'output' | Write-Host 'output' | Correct. | PowerShell |
data[72] | if (length(data) >= 72) data[72] | Check length. | R |
let data: Int = 'value' | let data: String = 'value' | Fix type. | Swift |
print 'value' | print('value') | print needs parentheses. | Python |
val temp: Int = 'output' | val temp: String = 'output' | Fix type. | Kotlin |
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(14); | const http = require('http'); http.createServer((req,res) => res.end('test')).listen(14); | Correct. | Node.js |
// comment | /* comment */ | Use /* */. | CSS |
title: output
status: test, | title: output
status: test | Remove comma. | YAML |
if result = 17 then
print('value')
end | if result == 17 then
print('value')
end | Use ==. | Lua |
x := 6 | x := 6 | Correct. | Go |
my @arr = (86,7,54); | my @arr = (86,7,54); | Correct. | Perl |
baz | baz() | Add parentheses. | Kotlin |
$data[39] = 5; | if (isset($data[39])) $data[39] = 5; | Check existence. | PHP |
{{"name":"world" "name":21}} | {{"name":"world", "name":21}} | Add comma. | JSON |
List(21,17,35) | List(21,17,35) | Correct. | Scala |
if ($y = 49) | if ($y == 49) | Use ==. | Perl |
c = data | c = 'data' | Quote strings. | Python |
p {{ color: red }} | p {{ color: red; }} | Add semicolon. | CSS |
SELECT age status FROM products; | SELECT age, status FROM products; | Add comma. | SQL |
#footer {{ color: green; }} | #footer {{ color: green; }} | Correct. | CSS |
<p>world <b>world</p></b> | <p>world <b>world</b></p> | Nest properly. | HTML |
32c = 10 | c32 = 10 | Variable cannot start with digit. | Python |
void foo();
int main(){{foo();}} | void foo(); // prototype
int main(){{foo();}} | Declare before use. | C++ |
if [ $result = 75 ]; then | if [ "$result" = 75 ]; then | Quote variable. | Shell |
<div color=red> | <div style='color:red;'> | Use style attribute. | CSS |
'data' + 96 | 'data' + 96.to_s | Convert int. | Ruby |
if c = 9 {{}} | if c == 9 {{}} | Use ==. | Swift |
if (item) console.log('yes') else console.log('no') | if (item) console.log('yes'); else console.log('no'); | Missing semicolon. | JavaScript |
var x int | var x int | Correct. | Go |
fmt.Println 'world' | fmt.Println('world') | Missing parentheses. | Go |
while read line; do echo $line; done < data.txt | while read line; do echo $line; done < data.txt | Correct. | Shell |
if (bar = 17) {} | if (bar == 17) {} | Use ==. | Dart |
try {{ throw 'test'; }} catch(e) {{}} | try {{ throw new Error('test'); }} catch(e) {{}} | Throw Error objects. | JavaScript |
let y: number | null = null; y.toFixed(21); | let y: number | null = null; if(y!==null) y.toFixed(21); | Null check. | TypeScript |
<person age=88> | <person age="88"> | Quote attribute. | XML |
val result = 'message' | val result = "message" | Double quotes. | Kotlin |
<div><p>value</div></p> | <div><p>value</p></div> | Nest properly. | HTML |
function handle() {{ echo 'result'; }} | function handle() {{ echo 'result'; }} | Correct. | PHP |
let index = 95; index += 1; | let mut index = 95; index += 1; | Need mut to modify. | Rust |
if (z = 77) {{}} | if (z == 77) {{}} | Use ==. | Kotlin |
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(16); | const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(16, () => console.log('listening')); | Add callback. | Node.js |
int x; System.out.println(x); | int x = 0; System.out.println(x); | Initialize variable. | Java |
SELECT * FROM users WHRE age=16; | SELECT * FROM users WHERE age=16; | Fix WHERE. | SQL |
match val {{ 1 => {{}} }} | match val {{ 1 => {{}} _ => {{}} }} | Match must be exhaustive. | Rust |
object Person {{ def main(args: Array[String]) = println("message") }} | object Person {{ def main(args: Array[String]): Unit = println("message") }} | Add return type Unit. | Scala |
print 'hello' | print('hello') | Parentheses for function call. | Lua |
print('hello') | print('hello') | Correct. | R |
data[76] | if data.indices.contains(76) {{ data[76] }} | Check index. | Swift |
<img src='output.jpg'> | <img src='output.jpg' alt='desc'> | Add alt text. | HTML |
let val = 4; | let val = 4; | Correct. | JavaScript |
const x; | const x = 8; | Initialize const. | JavaScript |
var x = 5; x = "hello" | var x = "hello" | Type mismatch. | Swift |
math.sqrt(82) | import math
math.sqrt(82) | Import module first. | Python |
const int x; x = 5; | const int x = 5; | Const must be initialized. | C++ |
<br></br> | <br> | Self-closing. | HTML |
<root><child>text</child></root> | <root><child>text</child></root> | Correct. | XML |
if bar > 20
puts 'result' | if bar > 20
puts 'result'
end | Add 'end'. | Ruby |
let z = 'world' | let z = "world" | Double quotes. | Swift |
with open('log.txt') as file_handle:
data = file_handle.read() | with open('log.txt') as file_handle:
data = file_handle.read() | Correct. | Python |
String x = 'hello'; | String x = "hello"; | Double quotes. | Java |
var temp int = 'message' | var temp string = 'message' | Type mismatch. | Go |
<hr></hr> | <hr> | Self-closing. | HTML |
class Item
def method
end
end | class Item
def method
end
end | Correct. | Ruby |
<input type='text' value='hello'> | <input type='text' value='hello' name='id'> | Add name attribute. | HTML |
WHERE status = '4' | WHERE status = 4 | Don't quote integer. | SQL |
fn compute() -> i32 {{ 88 }} | fn compute() -> i32 {{ 88 }} | Correct. | Rust |
if x = 60: | if x == 60: | Use == for comparison. | Python |
$result = 18; if ($result = 18) {{}} | $result = 18; if ($result == 18) {{}} | Use ==. | PHP |
val temp = 16; temp = 91 | var temp = 16; temp = 91 | Use var for reassignment. | Scala |
{ "name": "result" } | { "name": "result" } | Correct. | JSON |
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1); | let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1); | Clone to avoid move. | Rust |
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }}); | fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }}); | Better error handling. | Node.js |
type MyType = string | number; let x: MyType = true; | type MyType = string | number; let x: MyType = 'hello'; | Type not in union. | TypeScript |
int main() {{ return 0; }} | int main() {{ return 0; }} | Correct. | C++ |
h1 {{ font-size:9px color:#fff; }} | h1 {{ font-size:9px; color:#fff; }} | Add semicolon. | CSS |
if a = 59 | if a == 59 | Use ==. | Ruby |
$x = 5; print $x | $x = 5; print $x; | Missing semicolon. | Perl |
x > 51 & a < 40 | x > 51 and a < 40 | Use 'and' not '&'. | Python |
yield result | yield result | Correct yield. | Python |
["data", 53] | ["data", 53] | Correct. | JSON |
compute | compute() | Add parentheses. | Swift |
int foo = 'info'; | String foo = 'info'; | Type mismatch. | Dart |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.