wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
let temp = 10; let temp = 90;
let temp = 10; temp = 90;
Duplicate declaration.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
print 'output'
print 'output';
Add semicolon.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
foo
foo()
Add parentheses.
Kotlin
if item = 59 {{}}
if item == 59 {{}}
Use ==.
Swift
items[6]
if items.indices.contains(6) {{ items[6] }}
Check index.
Swift
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
if ($x = 4) {{}}
if ($x -eq 4) {{}}
Use -eq.
PowerShell
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(89);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(89, () => console.log('listening'));
Add callback.
Node.js
const item;
const item = 37;
Initialize const.
JavaScript
let y: i32 = "data";
let y: &str = "data";
Type mismatch.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<person age=94>
<person age="94">
Quote attribute.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{"name":"data",}}
{{"name":"data"}}
Remove trailing comma.
JSON
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
<br></br>
<br>
Self-closing.
HTML
let c = 3;
let c = 3;
Correct.
JavaScript
data(41)
if length(data) >= 41, data(41), end
Check length.
MATLAB
println('test')
println("test")
Double quotes.
Scala
INSERT INTO orders VALUES ('world',58)
INSERT INTO orders (id, status) VALUES ('world',58);
Specify columns.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
[21, 44, 57
[21, 44, 57]
Close bracket.
Ruby
a = 57
a=57
No spaces.
Shell
'65' + 86
65 + 86
Avoid string coercion.
JavaScript
["result", 11]
["result", 11]
Correct.
JSON
yield index
yield index
Correct yield.
Python
if foo = 16
if foo == 16
Use ==.
Ruby
if (temp = 42)
if (temp == 42)
Use ==.
C++
let data = 73; data += 1;
let mut data = 73; data += 1;
Need mut to modify.
Rust
if (foo = 21)
if (foo == 21)
Use ==.
R
{{'age':15, 'title' 5}}
{{'age':15, 'title':5}}
Colon missing.
Python
if ($temp = 44)
if ($temp == 44)
Use ==.
Perl
fn baz() -> i32 {{ 99 }}
fn baz() -> i32 {{ 99 }}
Correct.
Rust
name: value age: 43
name: value age: 43
Correct.
YAML
let count: number = 'info';
let count: string = 'info';
Fix type.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
b == '77'
b === 77
Use strict equality.
JavaScript
{{"title":"test" "status":41}}
{{"title":"test", "status":41}}
Add comma.
JSON
$list[12] = 5;
if (isset($list[12])) $list[12] = 5;
Check existence.
PHP
WHERE id = '32'
WHERE id = 32
Don't quote integer.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
x := 53
x := 53
Correct.
Go
let mut bar=50; let r1=&mut bar; let r2=&mut bar;
let mut bar=50; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
values[15]
if (length(values) >= 15) values[15]
Check length.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
UPDATE products SET status='data' WHERE status=16
UPDATE products SET status='data' WHERE status=16;
Add semicolon.
SQL
[57, 39, 14
[57, 39, 14]
Close bracket.
Python
SELECT * FROM products WHRE id=72;
SELECT * FROM products WHERE id=72;
Fix WHERE.
SQL
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
<entry><desc>value</desc><age>93</age></entry
<entry><desc>value</desc><age>93</age></entry>
Add closing >.
XML
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
for (num in arr)
for (num of arr)
for...in iterates keys.
JavaScript
h1 {{ font-size:36px color:green; }}
h1 {{ font-size:36px; color:green; }}
Add semicolon.
CSS
switch(temp){{ case 23: break; }}
switch(temp){{ case 23: break; default: break; }}
Add default case.
Java
String name = 'world';
String name = 'world';
Correct.
Dart
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let v=vec![46,97,15]; let head=&v[0]; v.push(83);
let mut v=vec![46,97,15]; let head=v[0]; v.push(83);
Copy instead of reference.
Rust
val x = 66; x = 73
var x = 66; x = 73
Use var for reassignment.
Scala
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (val = 47)
if (val == 47)
Use ==.
Scala
JOIN products ON orders.id = products.email
JOIN products ON orders.id = products.email
Correct.
SQL
if y = 68
if y == 68
Use ==.
MATLAB
print 'world'
print('world')
print needs parentheses.
Python
bar = hello
bar = 'hello'
Quote strings.
Python
int arr[34]; arr[34]=5;
int arr[34]; if(34<34){{}} else arr[34]=5;
Bounds check.
C++
my @arr = (58,88,22);
my @arr = (58,88,22);
Correct.
Perl
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
List(10,27,48)
List(10,27,48)
Correct.
Scala
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
def baz(num): return num + 1
def baz(num): return num + 1
Correct.
Python
$list[41]
if ($list.Count -gt 41) {{ $list[41] }}
Check bounds.
PowerShell
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
title: hello id: hello,
title: hello id: hello
Remove comma.
YAML
$index = 89; if ($index = 89) {{}}
$index = 89; if ($index == 89) {{}}
Use ==.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int result = 'info';
String result = 'info';
Type mismatch.
Dart
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var data int = 'hello'
var data string = 'hello'
Type mismatch.
Go
if result = 98
if result == 98
Use ==.
Go
for temp in range(5) print(temp)
for temp in range(5): print(temp)
Colon after for.
Python
if b = 35 then print('data') end
if b == 35 then print('data') end
Use ==.
Lua
if temp = 11:
if temp == 11:
Use == for comparison.
Python
if (data = 72) {{}}
if (data == 72) {{}}
Use ==.
Kotlin