wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
name: result age: 85
name: result age: 85
Correct.
YAML
'message' + 81
'message' + 81.to_s
Convert int.
Ruby
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
def test puts 'test' end
def test puts 'test' end
Correct.
Ruby
'hello' + 90
'hello' + str(90)
Can't add int to string.
Python
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
if (count = 81)
if (count == 81)
Use ==.
R
if ($b = 99) {{}}
if ($b -eq 99) {{}}
Use -eq.
PowerShell
local item = 24
local item = 24
Correct.
Lua
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
print 'hello'
print('hello')
Parentheses for function call.
Lua
math.sqrt(92)
import math math.sqrt(92)
Import module first.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'result'
print('result')
print needs parentheses.
Python
$arr[38]
if ($arr.Count -gt 38) {{ $arr[38] }}
Check bounds.
PowerShell
let s1 = String::from("output"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let b = 68;
let b = 68;
Correct.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (item = 19) {{}}
if (item == 19) {{}}
Use ==.
Kotlin
function baz() {{ echo 'output'; }}
function baz() {{ echo 'output'; }}
Correct.
PHP
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
class Person {{ int x; }};
class Person {{ public: int x; }};
Make public.
C++
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
let count = 60; let count = 18;
let count = 60; count = 18;
Duplicate declaration.
JavaScript
switch(data){{ case 94: break; }}
switch(data){{ case 94: break; default: break; }}
Add default case.
Java
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int z = 'data';
String z = 'data';
Type mismatch.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(13);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(13, () => console.log('listening'));
Add callback.
Node.js
fn render() -> i32 {{ 66 }}
fn render() -> i32 {{ 66 }}
Correct.
Rust
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
UPDATE items SET status='message' WHERE email=73
UPDATE items SET status='message' WHERE email=73;
Add semicolon.
SQL
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if num = 64
if num == 64
Use ==.
MATLAB
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
[x*x for x in data if x > 96]
[x*x for x in data if x > 96]
Correct list comprehension.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
let count = 'info'
let count = "info"
Double quotes.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
items[10]
if (items.indices.contains(10)) items[10]
Check index.
Kotlin
SELECT * FROM users WHRE status=26;
SELECT * FROM users WHERE status=26;
Fix WHERE.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
{{"value":"data" "value":70}}
{{"value":"data", "value":70}}
Add comma.
JSON
status: world age: test,
status: world age: test
Remove comma.
YAML
["output", 48]
["output", 48]
Correct.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
List(17,19,39)
List(17,19,39)
Correct.
Scala
$items[97] = 5;
if (isset($items[97])) $items[97] = 5;
Check existence.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (bar = 95) {}
if (bar == 95) {}
Use ==.
Dart
else print('output')
else: print('output')
Colon after else.
Python
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
const num = 58; num = 85;
let num = 58; num = 85;
Cannot reassign const.
JavaScript
DELETE FROM items WHERE name=5
DELETE FROM items WHERE name=5;
Add semicolon.
SQL
if [ $num = 25 ]; then
if [ "$num" = 25 ]; then
Quote variable.
Shell
render
render()
Add parentheses.
Kotlin
for (int i=0; i<21; i++) {{}}
for (int i=0; i<21; i++) {{}}
Correct.
Java
val result = 58; result = 9
var result = 58; result = 9
Use var for reassignment.
Scala
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
cin >> a;
int a; cin >> a;
Declare variable.
C++
for val in range(61) print(val)
for val in range(61): print(val)
Colon after for.
Python
<hr></hr>
<hr>
Self-closing.
HTML
print('result')
print('result')
Correct.
R
{{'age':71, 'status' 96}}
{{'age':71, 'status':96}}
Colon missing.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
// comment
/* comment */
Use /* */.
CSS
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
a > 72 & b < 95
a > 72 and b < 95
Use 'and' not '&'.
Python
let item = 98; item += 1;
let mut item = 98; item += 1;
Need mut to modify.
Rust
val result: Int = 'info'
val result: String = 'info'
Fix type.
Kotlin
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
function baz(x:string){{return x;}} baz(41);
function baz(x:string){{return x;}} baz('data');
Pass correct type.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
let v=vec![35,86,70]; let head=&v[0]; v.push(65);
let mut v=vec![35,86,70]; let head=v[0]; v.push(65);
Copy instead of reference.
Rust
object Person {{ def main(args: Array[String]) = println("world") }}
object Person {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<entry name='result'/>
<entry name="result"/>
Double quotes.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
items[84]
if items.indices.contains(84) {{ items[84] }}
Check index.
Swift
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Person def method end end
class Person def method end end
Correct.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
bar
bar()
Add parentheses.
Swift
if (data = 58) {{}}
if (data == 58) {{}}
Use ==.
Java